/Knowledge/sources/honojs__hono/examples/blog-src-api-ts--part-02--45e68b8443d4.md

Example: blog/src/api.ts (part 02) - hono-docs

Example: blog/src/api.ts (part 02) Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://raw.githubusercontent.com/honojs/examples/...

Example: blog/src/api.ts (part 02)

Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://raw.githubusercontent.com/honojs/examples/main/blog/src/api.ts

Summary

api.get('/posts/:id', async (c) => { const id = c.req.param('id') const post = await model.getPost(c.env.BLOG_EXAMPLE, id) if (!post) { return c.json({ error: 'Not Found', ok: false }, 404) } return c.json({ post: post, ok: true }) }) ap...

Content

api.get('/posts/:id', async (c) => { const id = c.req.param('id') const post = await model.getPost(c.env.BLOG_EXAMPLE, id) if (!post) { return c.json({ error: 'Not Found', ok: false }, 404) } return c.json({ post: post, ok: true }) })

api.put('/posts/:id', async (c) => { const id = c.req.param('id') const post = await model.getPost(c.env.BLOG_EXAMPLE, id) if (!post) { // 204 No Content return new Response(null, { status: 204 }) } const param = await c.req.json() const success = await model.updatePost(c.env.BLOG_EXAMPLE, id, param as model.Param) return c.json({ ok: success }) })

Metadata

{
  "chunk_index": 1,
  "citation": "https://raw.githubusercontent.com/honojs/examples/main/blog/src/api.ts",
  "coverage_role": "examples",
  "qualified_title": "Hono / examples / blog/src/api.ts (2)",
  "repo_path": "blog/src/api.ts",
  "retrieved_at": "2026-07-02T05:51:01Z",
  "section_index": 0,
  "source_id": "/honojs/hono",
  "source_type": "examples",
  "target_label": "examples",
  "title": "Example: blog/src/api.ts (part 02)",
  "upstream_url": "https://raw.githubusercontent.com/honojs/examples/main/blog/src/api.ts",
  "version": "2026"
}
Example: blog/src/api.ts (part 02) - hono-docs