server-routes

Implement HTTP API endpoints in TanStack Start using server route handlers.

Updated May 26, 2026
One-click install
npx skills add https://github.com/Albo-Club/albo-os --skill server-routes-albo-club
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: server-routes
Source: https://github.com/Albo-Club/albo-os/tree/main/.agents/skills/tanstack-start-core/server-routes
Command: npx skills add https://github.com/Albo-Club/albo-os --skill server-routes-albo-club

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building raw HTTP API endpoints inside a TanStack Start application requires knowing how to wire handlers to file-based routes, parse requests, and secure them correctly. This Skill provides the patterns for defining server routes with the server property on createFileRoute, so you can expose REST-style endpoints alongside your UI routes without a separate backend. ## Core Features & Use Cases - HTTP Method Handlers: Define GET, POST, PUT, and DELETE handlers that receive the raw Request object, route params, and middleware context. - Middleware Control: Apply middleware to all handlers at the route level or per-handler using createHandlers for fine-grained auth and validation. - File-Based API Routing: Map files like routes/api/users/$id.ts and splat routes ($.ts) to URL paths following TanStack Router conventions. - Use Case: You need a public webhook endpoint at /api/webhooks/stripe that parses a JSON body, verifies the caller via middleware, and returns a JSON response, while your SSR pages load the same data through server functions instead of fetching their own API. ## Quick Start Ask the AI to create a TanStack Start server route at src/routes/api/users.ts with GET and POST handlers that parse the request body and return JSON responses.

Frequently Asked Questions about server-routes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an API route in TanStack Start?

Create a file in src/routes and use the server property on createFileRoute with a handlers object keyed by HTTP method. Each handler receives the request, params, and context, and returns a standard Response such as Response.json(data).

When should I use server routes vs server functions in TanStack Start?

Use server routes when external callers need an HTTP contract, such as webhooks or third-party clients. For data consumed only by your own Start application, prefer createServerFn called directly from the loader instead of fetching your own API route.

How do I add middleware to a TanStack Start server route?

Pass a middleware array in the server config to run it for all handlers, or use createHandlers to attach middleware to specific methods. Route-level middleware runs first, followed by handler-specific middleware.

Does beforeLoad protect TanStack Start API routes?

No, a router beforeLoad redirect only guards the UI route and does not protect /api/... handlers. Every handler touching private data must authenticate through route middleware, handler middleware, or an in-handler check.

Why is my request body undefined in a TanStack Start handler?

Body methods like request.json(), request.text(), and request.formData() return Promises that must be awaited. Assigning request.json() without await leaves you with a pending Promise instead of the parsed data.