src/api/

The src/api/ folder contains your backend HTTP endpoints, where each .ts or .js file is auto-discovered as a route. The folder is named on app() as apiDir, in extensions.ts.

In the following example, extensions.ts names the folder explicitly and registers one extension, myPage:

Copy

A route is the file's path relative to that folder, with no prefix added. So src/api/orders.ts is served at /orders, and src/api/users/[id].ts at /users/:id. A file named index.ts serves its parent folder's route.

apiDir defaults to api, so a project that keeps its endpoints in src/api/ doesn't need to declare it. Only the folder in use is scanned, so an endpoint outside it isn't served.

Last updated: 10 November 2026

Did this help?