/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-status-code-be1c010fb064-status-code-s0050-c0000.md
Status code (1) - hono-docs
Status code (1) Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt status code Summary If you explic...
Status code (1)
Source evidence: /Sources/raw/honojshono/honojshono.md Canonical citation: https://hono.dev/llms-full.txt#status-code
Summary
If you explicitly specify the status code, such as 200 or 404, in c.json(), it will be added as a type for passing to the client. ```ts // server.ts const app = new Hono().get( '/posts', zValidator( 'query', z.object({ id: z.string...
Content
If you explicitly specify the status code, such as 200 or 404, in c.json(), it will be added as a type for passing to the client.
// server.ts
const app = new Hono().get(
'/posts',
zValidator(
'query',
z.object({
id: z.string(),
})
),
async (c) => {
const { id } = c.req.valid('query')
const post: Post | undefined = await getPost(id)
if (post === undefined) {
return c.json({ error: 'not found' }, 404) // Specify 404
}
return c.json({ post }, 200) // Specify 200
}
)
export type AppType = typeof appYou can get the data by the status code.