Skip to content

Lightweight, headless, path-based router with full type-safety. Think tRPC + REST

License

Notifications You must be signed in to change notification settings

AskingQuestions/typepath

Repository files navigation

TypePath

Think tRPC + REST

weekly downloads MIT License Discord

TypePath is a lightweight, headless router that has full type-safety.

Sample

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

Features

  • 💬 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

Quickstart

1. Installation

$ npm install typepath

2. Server

// 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;

3. Client

// 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!

About

Lightweight, headless, path-based router with full type-safety. Think tRPC + REST

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published