Chapter 3
Routing
Match URLs, read parameters, and return responses.
Routing
Routes connect HTTP methods and paths to handlers. A handler receives the request context and returns a response.
app.get('/chapters/:slug', (c) => {
const slug = c.req.param('slug')
return c.text(`Reading ${slug}`)
})
Parameters
Use path parameters when a route represents a family of resources. In this book, /chapters/:slug maps a chapter slug to a Markdown file.
const slug = c.req.param('slug')
Response helpers
Hono includes helpers for common response types:
c.text()for plain text.c.json()for JSON.c.html()for raw HTML or JSX.c.redirect()for redirects.
Those helpers keep route handlers short and easy to scan.