Routing and middleware

Design the route tree

Group resource routes, parameters, methods, and fallbacks into an inspectable API shape.

9 minute lesson

~~~

Before choosing a tool or writing more code, make the requirement concrete. The bookmarks router owns list, create, read, update, and delete paths under /bookmarks.

Hono routes match method and path in registration order, and grouped apps can own one coherent prefix. The useful target is not encyclopedic coverage. Make one deliberate choice, observe its consequences, and know which requirement would make you revise it.

A common failure is to scatter resource routes across files with overlapping wildcards and no route table. The happy path may still work, which makes the mistake easy to miss. write the route contract first, group one resource, and test literal, parameter, method, and not-found behavior. Keep the first version small enough that every important input and output remains visible.

This supports the module goal: Compose routes and middleware so the request path stays short, typed, and visible. Capture the request, command, trace, screenshot, test result, or other evidence that proves the result.

Build a route table and send requests that differ by method, trailing segment, invalid id, and unknown path. Change one condition on purpose, predict the result, and compare the prediction with what actually happened.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →