
TypePath is a lightweight, headless router that has full type-safety.
Here's a quick sample of what it looks like:
import { router, get } from "typepath";
const r = router({
"/welcome/:name": get((ctx) => `Hello, ${ctx.rawParams.name}!`),
});
r.get("/welcome/John"); // Hello, John!
// ⬆️ this is type-safe and will not compile if the path is incorrect
- 💬 Autocompletion for paths (including dynamic routes and string literals)
- 🚀 Fast and lightweight (~6kb gzipped)
- 📦 Return type-safe
buffers
,strings
,JSON
, raw responses, and more - 🖥️ Run it on any server (Express, Fastify, cloudflare, etc.)
- ✨ Use it for websockets, or any other protocol
- 🧹 No-codegen, no build step, 2 runtime dependencies (zod, superjson)
- 📖 Loads of docs and examples
$ npm install typepath
// server.ts
import { router, get } from "typepath";
// Create a router
const r = router({
"/": get((ctx) => "Hello, World!"),
});
// Listen on port 3000 using the default node:http server
r.listen({ port: 3000 });
export type Router = typeof r;
// client.ts
import { client } from "typepath";
import type { Router } from "./server";
// Create a client that points to the server
const c = client<Router>({
baseUrl: "http://localhost:3000",
});
console.log(await c.get("/")); // Hello, World!