Path Parameters in Hono

From the Hono cheat sheet · Routing · verified Jul 2026

Path Parameters

Extract dynamic values from URLs

typescript
// Single parameter
app.get('/users/:id', (c) => {
  const id = c.req.param('id')
  return c.json({ id })
})

// Multiple parameters
app.get('/posts/:postId/comments/:commentId', (c) => {
  const { postId, commentId } = c.req.param()
  return c.json({ postId, commentId })
})

// Optional parameter (using regex)
app.get('/books/:id{[0-9]+}?', (c) => {
  const id = c.req.param('id') // undefined if not provided
  return c.json({ id })
})
💡 c.req.param("name") gets single param, c.req.param() gets all
⚡ Use regex patterns for validation: :id{[0-9]+}
📌 Wildcard * captures everything after the path segment
🎯 Optional params: :param? matches with or without

More Hono tasks

Back to the full Hono cheat sheet