APIs & Routers
Val Town is a great place to serve an API because you can instantly deploy an API to a public URL and iterate very quickly.
One of the coolest things about using the web standard Request/Response API
in Val Town is that it works with modern web frameworks, so you can use routing
and their helper methods! When an HTTP file is deployed, it is available at a
subdomain like example.val.run, and requests to any subdirectory or path will
be routed to the file.
Hono
We typically recommend Hono, a modern alternative to Express.
Peko
With Peko:
nhttp
With nhttp:
itty-router
With itty-router:
feTS
With feTS server:
Notice, that it exports the router, which allows to use the
feTS client to make
routes type safe:
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);Missing your favorite framework?
Are we missing your routing framework of choice? Feel free to ask us, or open a branch to update this docs page.
Last updated