Build powerful APIs with Hono in Bini.js - file-based routing, middleware, and type safety.
Hono is a fast, lightweight web framework that works everywhere. Bini.js integrates Hono with file-based API routing - your file structure defines your API routes, and Hono routes are written without the /api prefix.
Your API route is determined by the file path inside src/app/api/. The file name becomes the route segment:
| File Path | API 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/* |
/api prefix - the framework strips it in dev/preview and mounts the app under /api in production.Create a Hono app in src/app/api/ and default export it. Because the API layer strips /api, the route you define for /api/hello is /hello.
Hono provides a powerful routing system with path parameters, query parameters, and more. Routes are written with the /api prefix stripped.
| Method | Route Pattern | Full URL |
|---|---|---|
| GET | /users | /api/users |
| GET | /users/:id | /api/users/123 |
| POST | /users | /api/users |
| PUT | /users/:id | /api/users/123 |
| DELETE | /users/:id | /api/users/123 |
Hono has built-in middleware for common tasks. Import from the subpath:
| Middleware | Import | Purpose |
|---|---|---|
| cors | hono/cors | Cross-Origin Resource Sharing |
| logger | hono/logger | Request logging |
| timeout | hono/timeout | Request timeout |
| secure-headers | hono/secure-headers | CSP and security headers |
| pretty-json | hono/pretty-json | Pretty JSON responses |
Hono provides convenient methods for accessing request data:
Validate incoming requests with Zod:
zod and @hono/zod-validator for request validation with TypeScript inference.Hono passes environment variables through the c.env object. Access them directly in your handlers:
wrangler secret put are read from c.env. On Node, c.env is backed by process.env.Handle errors gracefully with Hono's error handling:
| Scenario | Recommendation |
|---|---|
| Multiple endpoints in one file | Hono - Recommended |
| Need middleware (CORS, auth, logging) | Hono - Recommended |
| Complex routing patterns | Hono - Recommended |
| Production APIs with many routes | Hono - Recommended |
| Single endpoint with simple logic | Plain handler |
| Quick prototypes | Plain handler |
Files under app/api/ map to /api/*.
Backend endpoints with plain Request/Response handlers.
Path parameters and catch-all segments.
Read secrets with c.env in your API routes.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.
Fetch data before a route renders.
Build powerful APIs with Hono in Bini.js - file-based routing, middleware, and type safety.
Hono is a fast, lightweight web framework that works everywhere. Bini.js integrates Hono with file-based API routing - your file structure defines your API routes, and Hono routes are written without the /api prefix.
Your API route is determined by the file path inside src/app/api/. The file name becomes the route segment:
| File Path | API 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/* |
/api prefix - the framework strips it in dev/preview and mounts the app under /api in production.Create a Hono app in src/app/api/ and default export it. Because the API layer strips /api, the route you define for /api/hello is /hello.
Hono provides a powerful routing system with path parameters, query parameters, and more. Routes are written with the /api prefix stripped.
| Method | Route Pattern | Full URL |
|---|---|---|
| GET | /users | /api/users |
| GET | /users/:id | /api/users/123 |
| POST | /users | /api/users |
| PUT | /users/:id | /api/users/123 |
| DELETE | /users/:id | /api/users/123 |
Hono has built-in middleware for common tasks. Import from the subpath:
| Middleware | Import | Purpose |
|---|---|---|
| cors | hono/cors | Cross-Origin Resource Sharing |
| logger | hono/logger | Request logging |
| timeout | hono/timeout | Request timeout |
| secure-headers | hono/secure-headers | CSP and security headers |
| pretty-json | hono/pretty-json | Pretty JSON responses |
Hono provides convenient methods for accessing request data:
Validate incoming requests with Zod:
zod and @hono/zod-validator for request validation with TypeScript inference.Hono passes environment variables through the c.env object. Access them directly in your handlers:
wrangler secret put are read from c.env. On Node, c.env is backed by process.env.Handle errors gracefully with Hono's error handling:
| Scenario | Recommendation |
|---|---|
| Multiple endpoints in one file | Hono - Recommended |
| Need middleware (CORS, auth, logging) | Hono - Recommended |
| Complex routing patterns | Hono - Recommended |
| Production APIs with many routes | Hono - Recommended |
| Single endpoint with simple logic | Plain handler |
| Quick prototypes | Plain handler |
Files under app/api/ map to /api/*.
Backend endpoints with plain Request/Response handlers.
Path parameters and catch-all segments.
Read secrets with c.env in your API routes.
Deploy to Node, Vercel, Netlify, Cloudflare, or Deno.
Fetch data before a route renders.