Skip to content

Comments API Projesi

  • Tam kapsamlı API geliştirme
  • Hono ile D1 entegrasyonu
  • CRUD operations
Terminal window
npm create cloudflare@latest comments-api
cd comments-api
npm install hono
const app = new Hono<{ Bindings: Env }>();
// GET /api/posts/:slug/comments
app.get('/api/posts/:slug/comments', async (c) => {
const slug = c.req.param('slug');
const { results } = await c.env.DB
.prepare('SELECT * FROM comments WHERE post_slug = ?')
.bind(slug)
.run();
return c.json(results);
});
// POST /api/posts/:slug/comments
app.post('/api/posts/:slug/comments', async (c) => {
const slug = c.req.param('slug');
const { author, body } = await c.req.json();
const { success } = await c.env.DB
.prepare('INSERT INTO comments (author, body, post_slug) VALUES (?, ?, ?)')
.bind(author, body, slug)
.run();
return c.json({ success }, success ? 201 : 500);
});

✅ Tam kapsamlı API ✅ CRUD operations

Staff Directory Uygulaması - İkinci proje.


Ders Süresi: 90 dakika Zorluk Seviyesi: İleri