Edit on val.town ↗

Deploy an API endpoint in under a minute

An HTTP val is a fetch handler with a public URL: you write a function that takes a web-standard Request and returns a Response, and it's live at its own URL as soon as you save. There's no Dockerfile, no deploy pipeline, and nothing to provision.

This is a complete JSON API with one parameterized route, using Hono — the router we typically recommend:

import { Hono } from "npm:hono";

const app = new Hono();

app.get("/greet/:name", (c) =>
  c.json({ message: `Hello, ${c.req.param("name")}!` })
);

export default app.fetch;

If you don't need routes, skip Hono entirely and export a plain handler:

export default async function (req: Request): Promise<Response> {
  return Response.json({ ok: true });
}

  1. Create a val and add a file.
  2. Click the + button in the top right of the editor and select HTTP.
  3. Paste in the code above and save. The HTTP trigger shows your endpoint URL — something like yourname-api.web.val.run.

Then hit it from your terminal:

curl https://yourname-api.web.val.run/greet/world
{ "message": "Hello, world!" }

Requests to any path on that subdomain are routed to your file, so the /greet/:name route just works.

Last updated