Skip to content

Basic API

examples/basic-api in the Routa repository is the smallest complete project: a handful of routes, route-local schemas, and committed .routa/ metadata. Its route layout follows the scaffolder, with enough routes to show nesting and dynamic segments. Repository examples use Vite Plus for development; newly generated projects keep Biome and Vitest.

Terminal window
vp install --frozen-lockfile
vp run prepare:local-cli
vp run --filter basic-api dev
Terminal window
curl http://127.0.0.1:3000/users/usr_1

The response is a JSON user with ID usr_1. Creating a user returns 201 with a declared location header:

Terminal window
curl -i -X POST -H 'Content-Type: application/json' \
-d '{"email":"ada@example.com","name":"Ada"}' http://127.0.0.1:3000/users
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
location: /users/user_new

The development server listens on http://127.0.0.1:3000.

  • Directorysrc/
    • routa.ts
    • Directoryroutes/
      • Directorystatus/
        • route.ts
        • schemas.ts
      • Directoryusers/
        • route.ts
        • schemas.ts
        • Directory$userId/
          • route.ts
          • schemas.ts
          • Directoryposts/
            • route.ts
            • schemas.ts
      • Directorydemo/
        • route.ts

src/routes/users/route.ts and src/routes/users/$userId/route.ts show the two halves of a collection resource: one file owns /users, another owns /users/:userId. Neither knows about the other, because the URL comes from the file’s location rather than from a registry.

Every route keeps its Zod schemas in a sibling schemas.ts. That is the default convention, and it is what makes a route directory a self-contained unit you can move.

src/routes/users/$userId/posts/route.ts demonstrates that nesting continues past a dynamic segment: the parent parameter is still available in input.params because it is part of the resolved path.

File Shows
src/routa.ts The minimum configuration a project needs
src/routes/status/route.ts The smallest possible contract
src/routes/status/schemas.ts .describe() and .meta() documenting a response schema
src/routes/users/route.ts A collection, and a location header on 201
src/routes/users/$userId/route.ts A validated path parameter and a bodyless 204 DELETE
.routa/routes.gen.ts What Routa derived from all of the above

This example has no middleware, no authentication, no persistence, and no services. Handlers return in-memory data so the HTTP boundary stays legible, and their types have no ctx.services. For middleware chains, route groups, services, and OpenAPI workflows, read the Full API example.