$npx -y skills add yusukebe/hono-skill --skill honoUse when building Hono web applications or when the user asks about Hono APIs, routing, middleware, JSX, validation, testing, or streaming. TRIGGER when code imports from 'hono' or 'hono/*', or user mentions Hono. Use npx hono request to test endpoints.
| 1 | # Hono Skill |
| 2 | |
| 3 | Build Hono web applications. This skill provides inline API knowledge for AI. Use `npx hono request` to test endpoints. If the `hono-docs` MCP server is configured, prefer its tools for the latest documentation over the inline reference. |
| 4 | |
| 5 | ## Hono CLI Usage |
| 6 | |
| 7 | ### Request Testing |
| 8 | |
| 9 | Test endpoints without starting an HTTP server. Uses `app.request()` internally. |
| 10 | |
| 11 | ```bash |
| 12 | # GET request |
| 13 | npx hono request [file] -P /path |
| 14 | |
| 15 | # POST request with JSON body |
| 16 | npx hono request [file] -X POST -P /api/users -d '{"name": "test"}' |
| 17 | ``` |
| 18 | |
| 19 | **Note:** Do not pass credentials directly in CLI arguments. Use environment variables for sensitive values. `hono request` does not support Cloudflare Workers bindings (KV, D1, R2, etc.). When bindings are required, use `workers-fetch` instead: |
| 20 | |
| 21 | ```bash |
| 22 | npx workers-fetch /path |
| 23 | npx workers-fetch -X POST -H "Content-Type:application/json" -d '{"name":"test"}' /api/users |
| 24 | ``` |
| 25 | |
| 26 | --- |
| 27 | |
| 28 | ## Hono API Reference |
| 29 | |
| 30 | ### App Constructor |
| 31 | |
| 32 | ```ts |
| 33 | import { Hono } from 'hono' |
| 34 | |
| 35 | const app = new Hono() |
| 36 | |
| 37 | // With TypeScript generics |
| 38 | type Env = { |
| 39 | Bindings: { DATABASE: D1Database; KV: KVNamespace } |
| 40 | Variables: { user: User } |
| 41 | } |
| 42 | const app = new Hono<Env>() |
| 43 | ``` |
| 44 | |
| 45 | ### Routing Methods |
| 46 | |
| 47 | ```ts |
| 48 | app.get('/path', handler) |
| 49 | app.post('/path', handler) |
| 50 | app.put('/path', handler) |
| 51 | app.delete('/path', handler) |
| 52 | app.patch('/path', handler) |
| 53 | app.options('/path', handler) |
| 54 | app.all('/path', handler) // all HTTP methods |
| 55 | app.on('PURGE', '/path', handler) // custom method |
| 56 | app.on(['PUT', 'DELETE'], '/path', handler) // multiple methods |
| 57 | ``` |
| 58 | |
| 59 | ### Routing Patterns |
| 60 | |
| 61 | ```ts |
| 62 | // Path parameters |
| 63 | app.get('/user/:name', (c) => { |
| 64 | const name = c.req.param('name') |
| 65 | return c.json({ name }) |
| 66 | }) |
| 67 | |
| 68 | // Multiple params |
| 69 | app.get('/posts/:id/comments/:commentId', (c) => { |
| 70 | const { id, commentId } = c.req.param() |
| 71 | }) |
| 72 | |
| 73 | // Optional parameters |
| 74 | app.get('/api/animal/:type?', (c) => c.text('Animal!')) |
| 75 | |
| 76 | // Wildcards |
| 77 | app.get('/wild/*/card', (c) => c.text('Wildcard')) |
| 78 | |
| 79 | // Regexp constraints |
| 80 | app.get('/post/:date{[0-9]+}/:title{[a-z]+}', (c) => { |
| 81 | const { date, title } = c.req.param() |
| 82 | }) |
| 83 | |
| 84 | // Chained routes |
| 85 | app |
| 86 | .get('/endpoint', (c) => c.text('GET')) |
| 87 | .post((c) => c.text('POST')) |
| 88 | .delete((c) => c.text('DELETE')) |
| 89 | ``` |
| 90 | |
| 91 | ### Route Grouping |
| 92 | |
| 93 | ```ts |
| 94 | // Using route() |
| 95 | const api = new Hono() |
| 96 | api.get('/users', (c) => c.json([])) |
| 97 | |
| 98 | const app = new Hono() |
| 99 | app.route('/api', api) // mounts at /api/users |
| 100 | |
| 101 | // Using basePath() |
| 102 | const app = new Hono().basePath('/api') |
| 103 | app.get('/users', (c) => c.json([])) // GET /api/users |
| 104 | ``` |
| 105 | |
| 106 | ### Error Handling |
| 107 | |
| 108 | ```ts |
| 109 | app.notFound((c) => c.json({ message: 'Not Found' }, 404)) |
| 110 | |
| 111 | app.onError((err, c) => { |
| 112 | console.error(err) |
| 113 | return c.json({ message: 'Internal Server Error' }, 500) |
| 114 | }) |
| 115 | ``` |
| 116 | |
| 117 | --- |
| 118 | |
| 119 | ## Context (c) |
| 120 | |
| 121 | ### Response Methods |
| 122 | |
| 123 | ```ts |
| 124 | c.text('Hello') // text/plain |
| 125 | c.json({ message: 'Hello' }) // application/json |
| 126 | c.html('<h1>Hello</h1>') // text/html |
| 127 | c.redirect('/new-path') // 302 redirect |
| 128 | c.redirect('/new-path', 301) // 301 redirect |
| 129 | c.body('raw body', 200, headers) // raw response |
| 130 | c.notFound() // 404 response |
| 131 | ``` |
| 132 | |
| 133 | ### Headers & Status |
| 134 | |
| 135 | ```ts |
| 136 | c.status(201) |
| 137 | c.header('X-Custom', 'value') |
| 138 | c.header('Cache-Control', 'no-store') |
| 139 | ``` |
| 140 | |
| 141 | ### Variables (request-scoped data) |
| 142 | |
| 143 | ```ts |
| 144 | // In middleware |
| 145 | c.set('user', { id: 1, name: 'Alice' }) |
| 146 | |
| 147 | // In handler |
| 148 | const user = c.get('user') |
| 149 | // or |
| 150 | const user = c.var.user |
| 151 | ``` |
| 152 | |
| 153 | ### Environment (Cloudflare Workers) |
| 154 | |
| 155 | ```ts |
| 156 | const value = await c.env.KV.get('key') |
| 157 | const db = c.env.DATABASE |
| 158 | c.executionCtx.waitUntil(promise) |
| 159 | ``` |
| 160 | |
| 161 | ### Renderer |
| 162 | |
| 163 | ```ts |
| 164 | app.use(async (c, next) => { |
| 165 | c.setRenderer((content) => |
| 166 | c.html( |
| 167 | <html><body>{content}</body></html> |
| 168 | ) |
| 169 | ) |
| 170 | await next() |
| 171 | }) |
| 172 | |
| 173 | app.get('/', (c) => c.render(<h1>Hello</h1>)) |
| 174 | ``` |
| 175 | |
| 176 | --- |
| 177 | |
| 178 | ## HonoRequest (c.req) |
| 179 | |
| 180 | ```ts |
| 181 | c.req.param('id') // path parameter |
| 182 | c.req.param() // all path params as object |
| 183 | c.req.query('page') // query string parameter |
| 184 | c.req.query() // all query params as object |
| 185 | c.req.queries('tags') // multiple values: ?tags=A&tags=B → ['A', 'B'] |
| 186 | c.req.header('Authorization') // request header |
| 187 | c.req.header() // all headers (keys are lowercase) |
| 188 | |
| 189 | // Body parsing |
| 190 | await c.req.json() // parse JSON body |
| 191 | await c.req.text() // parse text body |
| 192 | await c.req.formData() // parse as FormData |
| 193 | await c.req.parseBody() // parse multipart/form-data or urlencoded |
| 194 | await c.req.arrayBuffer() // parse as ArrayBuffer |
| 195 | await c.req.blob() // parse as Blob |
| 196 | |
| 197 | // Validated data (used with validator middleware) |
| 198 | c.req.valid('json') |
| 199 | c.req.valid('query') |
| 200 | c.req.valid('form') |
| 201 | c.req.valid('param') |
| 202 | |
| 203 | // Properties |
| 204 | c.req.url // full URL string |
| 205 | c.req.path // pathname |
| 206 | c.req.method // HTTP method |
| 207 | c.req.raw // underlying Request object |
| 208 | ``` |
| 209 | |
| 210 | --- |
| 211 | |
| 212 | ## Middleware |
| 213 | |
| 214 | ### Using Built-in Middleware |
| 215 | |
| 216 | ```ts |
| 217 | import { cors } from 'hono/cors' |
| 218 | import |