Skip to Content
Schema-first · Type-safe · Transport-agnostic

routar

Define your API schema once — get end-to-end type safety and runtime validation across any HTTP client and any environment.

Get Started →Why routar?
npm install @routar/core
import { z } from 'zod'
import { endpoint, defineRouter, createApi, createFetchExecutor } from '@routar/core'

const TodoSchema = z.object({ id: z.number(), title: z.string(), done: z.boolean() })

const api = createApi(createFetchExecutor('https://api.example.com'), defineRouter('/todos', {
  list:   endpoint({ method: 'GET',  path: '/',    response: z.array(TodoSchema) }),
  detail: endpoint({ method: 'GET',  path: '/:id', response: TodoSchema,
                     request: z.object({ path: z.object({ id: z.number() }) }) }),
  create: endpoint({ method: 'POST', path: '/',    response: TodoSchema,
                     request: z.object({ body: z.object({ title: z.string() }) }) }),
}))

const todos = await api.list({})                              // Todo[]
const todo  = await api.detail({ path: { id: 1 } })          // Todo
const next  = await api.create({ body: { title: 'buy milk' } }) // Todo

Composable by design

Mix and match anything

Swap executors, stack plugins, combine routers.
The types assemble themselves.

Routers
Create with
Executor
Plugins
🔒
End-to-end types
Request params and response shape — all inferred without any.
Runtime validation
Zod, Valibot, Yup, or any .parse() — validates both sides.
🔌
Transport agnostic
Swap fetch or Axios in one line. Schema stays the same.
🧱
Middleware
Retry, timeout, logging — stackable, composable functions.
🗂️
Nested routers
URL structure mirrors the type system naturally.
🌐
SSR / CSR ready
Same spec, different executor per environment.

Packages

@routar/core
Endpoint definitions, router, API client factory, fetch executor, and middleware.
npm install @routar/core
@routar/axios
Axios executor. Works with existing instances and interceptors.
npm install @routar/axios
@routar/ky
ky executor. Lightweight fetch wrapper with hooks support.
npm install @routar/ky
@routar/msw
MSW v2 handler factory — generate typed mock handlers from your RouterDef for testing.
npm install @routar/msw
@routar/react-query
TanStack Query bindings for routar — queryOptions/mutationOptions factories from a routar router
npm install @routar/react-query
Getting StartedWhy routar?API ReferenceGuides