Skip to content

Routing

One of the coolest things about the Request/Response API is that it works with modern web frameworks, so you can use routing and their helper methods!

Hono

Here’s an example with Hono:

Hono exampleRun in Val Town ↗
import { Hono } from "npm:hono@3";
const app = new Hono();
app.get("/", (c) => c.text("Hello world!"));
app.get("/yeah", (c) => c.text("Routing!"));
export default app.fetch;

Peko

And one with Peko:

Peko exampleRun in Val Town ↗
import { Peko } from "https://deno.land/x/peko@2.0.0/mod.ts";
export const pekoExample = async (request) => {
const server = new Peko.Router();
server.get("/", () => new Response("Yes? There's something at /hello"));
server.get("/hello", () => new Response("Hello world!"));
return server.requestHandler(request);
};

nhttp

And nhttp:

NHttp exampleRun in Val Town ↗
import { nhttp } from "npm:nhttp-land@1";
export const nhttpExample = async (request) => {
const app = nhttp();
app.get("/", () => {
return "Hello, World";
});
app.get("/cat", () => {
return { name: "cat" };
});
return app.handleRequest(request);
};

itty-router

A super tiny example with itty-router:

Itty exampleRun in Val Town ↗
import { Router, json } from "npm:itty-router@4";
export const ittyRouterExample = async (request: Request) => {
const router = Router();
router.get("/", () => "Hi");
return router.handle(request).then(json);
};