Typesafe API Routes
End-to-end type safety from server to client. Define routes with Zod schemas and get full type inference.
API Tester
Test API endpoints with full type safety
How Typesafe APIs Work
- Define routes with Zod schemas for params, query, body, and response
- Compose routes into an API object using
createAPI() - Generate typesafe client with
apiClient - Use the client in components - all types are inferred automatically
Code Examples
// src/api/users.ts
import { z } from "zod";
import { route } from "~/framework/shared/api";
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
});
export const byId = route({
method: "GET",
params: z.object({ id: z.string() }),
response: userSchema,
handler: ({ params }) => getUser(params.id),
});
export const create = route({
method: "POST",
body: z.object({
name: z.string(),
email: z.string().email()
}),
response: userSchema,
handler: ({ body }) => createUser(body),
});Benefits
- End-to-end type safety - catch errors at compile time
- Auto-completion in IDE - no guessing API shapes
- Runtime validation with Zod - invalid requests are rejected
- Single source of truth - define schema once, use everywhere
- Refactor-safe - changing schemas updates all usages