Backend endpoints with plain Request handlers or Hono. Files under app/api/ map to /api/*.
Place .ts or .js files in src/app/api/ and they become routes at /api/*. Every handler receives a standard Web Request and a context object.
| File | Route |
|---|---|
| src/app/api/hello.ts | /api/hello |
| src/app/api/users.ts | /api/users |
| src/app/api/posts/index.ts | /api/posts |
| src/app/api/posts/[id].ts | /api/posts/:id |
| src/app/api/[...catch].ts | /api/* |
The filename becomes the last path segment under /api/. Use index.ts inside a folder for the parent path. API files are marked with the ƒ icon.
_ or . are ignored.Three handler styles are supported. All receive a Web Request and return a Response.
Export GET, POST, PUT, PATCH, DELETE, HEAD, or OPTIONS. Other methods receive 405 with an Allow header, and HEAD falls back to GET.
A default export with a .fetch() method - such as a Hono instance - is mounted under /api. Write Hono routes without the /api prefix.
Every handler receives a context object with these fields.
| Field | Type | Description |
|---|---|---|
| params | object | Dynamic route params (e.g. { id: "123" }) |
| searchParams | URLSearchParams | Query string parameters |
| env | any | Runtime env bindings (or process.env on Node) |
| waitUntil? | function | Extends the request lifetime for background work |
[id] folders or files create dynamic segments. [...catch] matches the remaining segments. Catch-all values are available under params['*'] and under the folder name.
Access environment variables directly from the env object in the request context. This ensures your code works across all deployment platforms.
env is backed by process.env. On edge platforms, it reads the runtime bindings.CORS is off by default. Enable it at the router level with an explicit origin allowlist, or handle it per-route with Hono middleware.
origin list in production. Setting cors: true allows any origin.API routes work across platforms. The deploy tool generates the platform entry files for non-Node hosts.
| Platform | Entry |
|---|---|
| Node.js | The production server reads dist/api/index.mjs directly |
| Netlify | netlify/functions/api.mjs |
| Vercel | api/index.ts |
| Cloudflare | worker.ts |
| Deno | server/index.ts |
Backend endpoints with plain Request/Response handlers.
Build API routes with the Hono framework.
Path parameters and catch-all segments.
Read secrets in your API routes.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.
Fetch data before a route renders.
Backend endpoints with plain Request handlers or Hono. Files under app/api/ map to /api/*.
Place .ts or .js files in src/app/api/ and they become routes at /api/*. Every handler receives a standard Web Request and a context object.
| File | Route |
|---|---|
| src/app/api/hello.ts | /api/hello |
| src/app/api/users.ts | /api/users |
| src/app/api/posts/index.ts | /api/posts |
| src/app/api/posts/[id].ts | /api/posts/:id |
| src/app/api/[...catch].ts | /api/* |
The filename becomes the last path segment under /api/. Use index.ts inside a folder for the parent path. API files are marked with the ƒ icon.
_ or . are ignored.Three handler styles are supported. All receive a Web Request and return a Response.
Export GET, POST, PUT, PATCH, DELETE, HEAD, or OPTIONS. Other methods receive 405 with an Allow header, and HEAD falls back to GET.
A default export with a .fetch() method - such as a Hono instance - is mounted under /api. Write Hono routes without the /api prefix.
Every handler receives a context object with these fields.
| Field | Type | Description |
|---|---|---|
| params | object | Dynamic route params (e.g. { id: "123" }) |
| searchParams | URLSearchParams | Query string parameters |
| env | any | Runtime env bindings (or process.env on Node) |
| waitUntil? | function | Extends the request lifetime for background work |
[id] folders or files create dynamic segments. [...catch] matches the remaining segments. Catch-all values are available under params['*'] and under the folder name.
Access environment variables directly from the env object in the request context. This ensures your code works across all deployment platforms.
env is backed by process.env. On edge platforms, it reads the runtime bindings.CORS is off by default. Enable it at the router level with an explicit origin allowlist, or handle it per-route with Hono middleware.
origin list in production. Setting cors: true allows any origin.API routes work across platforms. The deploy tool generates the platform entry files for non-Node hosts.
| Platform | Entry |
|---|---|
| Node.js | The production server reads dist/api/index.mjs directly |
| Netlify | netlify/functions/api.mjs |
| Vercel | api/index.ts |
| Cloudflare | worker.ts |
| Deno | server/index.ts |
Backend endpoints with plain Request/Response handlers.
Build API routes with the Hono framework.
Path parameters and catch-all segments.
Read secrets in your API routes.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.
Fetch data before a route renders.