Getting Started
Installation
With fetch (built into core — zero extra dependencies):
npm install @routar/coreWith Axios:
npm install @routar/core @routar/axios axiosSet up with an AI agent
Paste this into Cursor, Claude Code, or any AI coding assistant:
Add routar (
@routar/core) as the API client for this project. First fetch the latest routar docs — via Context7 (use context7) if that MCP server is set up, otherwise fetch https://routar.vercel.app/llms-full.txt directly. Check package.json for an existing HTTP client: use@routar/axiosifaxiosis already a dependency,@routar/kyifkyis, otherwise use the built-in fetch executor. Then set it up: define Zod schemas for the API models, group endpoints withendpoint()+defineRouter(), and build the typed client with the chosen executor +createApi(). If@tanstack/react-queryis already a dependency, don’t wire up@routar/react-queryyet — ask me first, then follow up as a separate step, since it touches query keys and provider setup across the app.
Quick Start
1. Define your schema
import { z } from 'zod'
const TodoSchema = z.object({
id: z.number(),
title: z.string(),
completed: z.boolean(),
})2. Define endpoints and router
import { endpoint, defineRouter } from '@routar/core'
const todoRouter = defineRouter('/todos', {
getList: endpoint({
method: 'GET',
path: '/',
response: z.array(TodoSchema),
}),
getDetail: endpoint({
method: 'GET',
path: '/:id',
request: { path: z.object({ id: z.number() }) },
response: TodoSchema,
}),
create: endpoint({
method: 'POST',
path: '/',
request: { body: z.object({ title: z.string() }) },
response: TodoSchema,
}),
})3. Create executor and API client
import { createApi } from '@routar/core'
import { createFetchExecutor } from '@routar/core'
const executor = createFetchExecutor('https://api.example.com')
const todoApi = createApi(executor, todoRouter)4. Make requests
const todos = await todoApi.getList({})
const todo = await todoApi.getDetail({ path: { id: 1 } })
const next = await todoApi.create({ body: { title: 'buy milk' } })All return types are fully inferred — no type annotations needed. In your IDE, hovering over todos shows Todo[] and todo shows Todo.
AbortSignal
Pass an AbortSignal as the second argument to cancel in-flight requests:
const controller = new AbortController()
const todos = await todoApi.getList({}, controller.signal)
controller.abort() // cancels the requestWith Plugins
import { createFetchExecutor, logger } from '@routar/core'
const executor = createFetchExecutor('https://api.example.com', {
plugins: [logger()],
retry: 3,
timeout: 8_000,
})With Axios
import axios from 'axios'
import { createAxiosExecutor } from '@routar/axios'
const executor = createAxiosExecutor(
axios.create({ baseURL: 'https://api.example.com' })
)Next Steps
- Example app — a full Next.js app using every package, SSR + CSR, and TanStack Query
- API Reference — full documentation for every export
- Executors — fetch vs. axios, SSR/CSR patterns
- Guides — SSR/CSR, custom executors, error handling