AI Integration
Writing code is cheap. Keeping it consistent isn’t — and that gap widens as AI generates more code, faster. This page covers routar’s value in the AI era and the machine-readable resources that make AI coding assistants (Claude Code, Copilot, Cursor) routar-aware.
Less boilerplate. Less drift.
Writing code is cheap now — AI generates fetch wrappers, types, and hooks at near-zero cost. Keeping that code consistent as the API evolves is still expensive.
Without routar, one API endpoint typically lives in five separate representations: a fetch function, a TypeScript type, a query key, a query hook, and an MSW mock. Change the endpoint — update five things, or ship drift.
routar collapses those five representations into one endpoint() definition. Client function, TypeScript types, TanStack Query keys, and MSW handlers all derive from it automatically:
// One contract — everything else is derived
const todoRouter = defineRouter('/todos', {
getDetail: endpoint({
method: 'GET',
path: '/:id',
request: { path: z.object({ id: z.number() }) },
response: TodoSchema,
}),
})
// Typed client, query keys, MSW handlers — all consistent, no duplication
export const todoQuery = createQueries(createApi(executor, todoRouter))Change the endpoint; edit one endpoint(), and everything downstream follows.
A few properties reinforce this at the boundaries:
- Compile-time path-param enforcement — a missing or renamed
:paramin a call fails to type-check, not at runtime. - Runtime response validation — when the backend changes, the schema catches it at the boundary instead of letting
undefinedpropagate silently. - Single source of truth — client, types, query keys, and MSW mocks all derive from the same definition. There are fewer places for inconsistency to hide.
Less boilerplate isn’t just less to write. It’s fewer representations of the same fact — and fewer places for drift.
llms.txt
Two machine-readable documentation files are available at the root of this site:
| URL | Purpose |
|---|---|
/llms.txt | Concise API index — all exports with one-line descriptions |
/llms-full.txt | Full API reference with signatures and code examples |
These follow the llms.txt standard . You can point any AI tool directly at these URLs for up-to-date routar documentation.
AGENTS.md
AGENTS.md at the repository root is a reference guide for AI agents. It covers the core patterns, executor selection, SSR/CSR setup, MSW testing, and common anti-patterns.
Copy the relevant sections into your own project’s AGENTS.md so AI assistants understand how your API layer is structured:
<!-- In your project's AGENTS.md -->
## API layer
This project uses routar. See https://github.com/minr2kb/routar/blob/main/AGENTS.md
for patterns, executor selection, and anti-patterns.IDE experience (JSDoc)
Every exported function in @routar/core and @routar/msw ships with @example blocks in the published .d.ts files. Hover docs and inline suggestions work immediately after npm install — no configuration needed.
// Hover over endpoint( in your editor:
endpoint({
method: 'GET',
path: '/:id',
request: { path: z.object({ id: z.number() }) },
response: TodoSchema,
});
// Hover over createMswHandlers( in your editor:
const server = setupServer(
...createMswHandlers(todoRouter, 'https://api.example.com', {
getList: () => HttpResponse.json([]),
getDetail: ({ params }) => HttpResponse.json({ id: params.id }),
}),
);