Create dynamic API endpoints with path parameters, catch-all routes, and optional segments.
Dynamic API routes match patterns instead of exact paths. Wrap a segment in square brackets in the file or folder name - the file path determines the route.
/api prefix.| Pattern | Meaning | Example Matches |
|---|---|---|
| [id] | Single dynamic segment | /api/posts/123, /api/posts/abc |
| [category]/[slug] | Multiple dynamic segments | /api/posts/tech/hello-world |
| [...path] | Catch-all (required, 1+ segments) | /api/files/a, /api/files/a/b/c |
| [[...slug]] | Catch-all (optional, 0+ segments) | /api/docs, /api/docs/a/b |
Use [name] in the filename to capture a single dynamic segment.
Plain handlers receive path params on the second argument, as { params }:
Combine multiple dynamic segments in a single route:
| URL | params |
|---|---|
| /api/posts/tech/hello-world | { category: "tech", slug: "hello-world" } |
| /api/posts/lifestyle/tips | { category: "lifestyle", slug: "tips" } |
Use [...name] in the filename to match one or more path segments. In Hono, the catch-all is written as :name*.
| URL | path value |
|---|---|
| /api/files/images | images |
| /api/files/images/2024 | images/2024 |
| /api/files/docs/api/reference | docs/api/reference |
A top-level [...catch] file under src/app/api/ handles any request that no other API route matches:
Use [[...name]] to make the catch-all optional, so the base path also matches. In Hono, this is written as :name*?.
| URL | slug value |
|---|---|
| /api/docs | undefined (base path) |
| /api/docs/getting-started | getting-started |
| /api/docs/api/reference | api/reference |
Combine static and dynamic segments for deeper routing:
Combine dynamic path parameters with query strings:
When multiple routes could match a URL, Bini.js resolves them in this order:
[id][...slug][[...slug]]A full-featured store API using dynamic and catch-all routing:
Files under app/api/ map to /api/*.
Simple Request → Response endpoints.
Routing, middleware, and validation with Hono.
Handle unmatched paths and segments.
Create dynamic API endpoints with path parameters, catch-all routes, and optional segments.
Dynamic API routes match patterns instead of exact paths. Wrap a segment in square brackets in the file or folder name - the file path determines the route.
/api prefix.| Pattern | Meaning | Example Matches |
|---|---|---|
| [id] | Single dynamic segment | /api/posts/123, /api/posts/abc |
| [category]/[slug] | Multiple dynamic segments | /api/posts/tech/hello-world |
| [...path] | Catch-all (required, 1+ segments) | /api/files/a, /api/files/a/b/c |
| [[...slug]] | Catch-all (optional, 0+ segments) | /api/docs, /api/docs/a/b |
Use [name] in the filename to capture a single dynamic segment.
Plain handlers receive path params on the second argument, as { params }:
Combine multiple dynamic segments in a single route:
| URL | params |
|---|---|
| /api/posts/tech/hello-world | { category: "tech", slug: "hello-world" } |
| /api/posts/lifestyle/tips | { category: "lifestyle", slug: "tips" } |
Use [...name] in the filename to match one or more path segments. In Hono, the catch-all is written as :name*.
| URL | path value |
|---|---|
| /api/files/images | images |
| /api/files/images/2024 | images/2024 |
| /api/files/docs/api/reference | docs/api/reference |
A top-level [...catch] file under src/app/api/ handles any request that no other API route matches:
Use [[...name]] to make the catch-all optional, so the base path also matches. In Hono, this is written as :name*?.
| URL | slug value |
|---|---|
| /api/docs | undefined (base path) |
| /api/docs/getting-started | getting-started |
| /api/docs/api/reference | api/reference |
Combine static and dynamic segments for deeper routing:
Combine dynamic path parameters with query strings:
When multiple routes could match a URL, Bini.js resolves them in this order:
[id][...slug][[...slug]]A full-featured store API using dynamic and catch-all routing:
Files under app/api/ map to /api/*.
Simple Request → Response endpoints.
Routing, middleware, and validation with Hono.
Handle unmatched paths and segments.