Course lesson 13 · Smart Routing Service
Setting up Hono
Hono adds a small routing layer inside the data-service Worker so the application can define paths without manually inspecting each URL. The Worker remains the entrypoint and forwards the request, environment, and execution context to the Hono app. A dynamic ID route initially returns JSON, establishing the seam where real short-link logic will be added.
Primary source: course video 13 · Supplied English subtitles · 00:08:26.
Understand the idea
- The Worker entrypoint receives the event; Hono decides which application route handles its HTTP path.
- A dynamic /:id route captures the short-link identifier while leaving the homepage unimplemented.
- Hono’s context exposes request helpers, response helpers, and environment bindings to each route.
- Typing the app’s bindings with the generated environment type provides completion and checking when accessing Cloudflare resources.
- The execution context includes waitUntil, introduced as a way to continue limited asynchronous work after returning a response; later lessons apply it.
What the course does
- Keep the existing WorkerEntrypoint class and create a separate Hono app module in the data service.
- Ensure Hono is installed, export the app, and specify the application’s environment bindings type.
- Define a GET route with a dynamic ID parameter and return a small JSON response.
- Replace the Worker’s hello-world response with forwarding to the Hono app’s fetch handler.
- Forward all three pieces of context: the incoming request, Worker environment, and execution context.
- Run locally and compare the unmatched homepage with an arbitrary ID path that matches the new route.
Watch for
- Omitting the environment when forwarding prevents the route from accessing its bindings, even if Wrangler configuration is correct.
- A not-found response at the homepage is expected because only the ID route has been defined.
- Added advice: waitUntil is not a substitute for the durable queue and workflow mechanisms that the course introduces for more substantial background processing.
Recall before revealing
Why must the Worker forward more than the request to Hono?
Reveal the explanation
The routes also need the runtime environment for bindings and the execution context for Cloudflare-specific request-lifecycle capabilities.
Try it
Add the Hono ID route and inspect responses for / and /sample-link in your local data service.
Check your result
The ID route returns JSON, the homepage is unmatched, and you can trace the same request through the Worker and Hono layers.
Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.
Rewatch only what you need
Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.
- 00:00:00 — Why manual path conditions become cumbersome
- 00:03:00 — Create the typed Hono app and dynamic route
- 00:05:01 — Forward the Worker request and context
- 00:07:00 — Test matched and unmatched paths
Companion primary documentation: Hono on Cloudflare Workers. For recorded API names, commands, limits, and prices, check the version you use.