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! When an HTTP val is deployed, it is available at a subdomain like handle-valname.web.val.run, and requests to any subdirectory or path will be routed to the val.

Hono

Here’s an example with Hono:

Peko

And one with Peko:

nhttp

And nhttp:

itty-router

A super tiny example with itty-router:

feTS

A simple example of using feTS server:

Notice, that it exports the router, which allows to use the feTS client to make routes type safe:

@user/fetsClientRun in Val Town ↗
import { type router } from "https://esm.town/v/user/fetsServer";
import { createClient } from "npm:fets";
const client = createClient<typeof router>({
endpoint: "https://user-fetsServer.web.val.run",
});
// The `response` and `greetings` have proper types automatically inferred
const response = await client["/greetings"].get();
const greetings = await response.json();
console.log(greetings);
Fork it on