API routes let you create HTTP endpoints in your One app. Add +api.ts to the end of your filename and export handler functions for each HTTP method.
app/api/hello+api.ts
This creates an endpoint at /api/hello that responds to GET requests.
Export named functions for each HTTP method:
app/api/users+api.ts
You can also export a default function as a catch-all:
Use brackets for dynamic segments. Params are passed as the second argument:
app/api/users/[id]+api.ts
Rest parameters work the same way:
app/api/files/[...path]+api.ts
API routes use the standard Web Request and Response APIs. TypeScript and Node >= 20 include these globally.
One exports an Endpoint type for simple cases:
For typed params, use createAPIRoute:
Edit this page on GitHub.