API foundations
Return the first resource
Create a GET route that returns a predictable JSON collection and an explicit HTTP success response.
8 minute lesson
Begin with an in-memory collection so the first route tests only the API layer.
Hono’s context creates a JSON Response with the correct content type. Keep response data consistent: return a named collection rather than sometimes returning an array and sometimes an object.
import { Hono } from 'hono'
const app = new Hono()
const books = [{ id: '1', title: 'Dune', author: 'Frank Herbert' }]
app.get('/books', c => c.json({ books }))
export default app
The envelope { books: [...] } leaves room for pagination links or metadata without changing the top-level type later. An empty collection is still a successful collection response: return 200 with { books: [] }, not 404 and not a different shape.
Treat the response as observable evidence. Confirm the status, content-type, and exact JSON keys. Mutation of the in-memory array will be shared by later requests in this one server process, which is useful for learning but not durable storage. Restart the process and verify that the seed data returns; that failure is the reason the data module later moves behind a database boundary.
Add the route and request it with curl and the browser network panel.
Lesson completed