Skip to main content
An API route is a file under app/api/ (or pages/api/) that exports named HTTP method handlers. Handlers receive the standard Web Request and return a Response. The router style changes the file location and the handler’s argument shape. The request and response APIs are the same in both.

Prerequisites

  • A project created with veryfront init (see Create project).
  • The dev server running (veryfront dev) or a build target you can hit with HTTP.

Router module shapes

Use app/api/**/route.ts in the app router. Export named HTTP method handlers. Each handler receives the Request directly and receives route params in the second argument.
Use pages/api/** in the pages router. Export named HTTP method handlers or a default fallback handler. Each handler receives an APIContext as ctx; use ctx.request for the raw request, ctx.params for route params, ctx.query for query parameters, and ctx.json() or Response.json() to return JSON.

Basic route

This creates GET /api/hello. Try it with the dev server running:
The response should be:

HTTP methods

Export any standard HTTP method:
The same pages router route uses ctx:

Dynamic parameters

Use brackets in the path, then read params from the route context:
In the pages router, params are available on ctx.params:

Request parsing

JSON body

Form data

Query parameters

Headers and cookies

Streaming responses

Return a ReadableStream for real-time data:

Chat endpoint

The most common API route pattern in Veryfront connects a chat UI to an agent:
Messages use Veryfront’s parts-based chat message format with id, role, and parts fields. The route responds with AG-UI SSE and pairs with useChat configured for /api/ag-ui on the client. See the Chat UI guide.

Verify it worked

Call each handler with curl from another terminal while veryfront dev is running:
A working handler returns the expected status code and a JSON or streamed body. A 404 means the file path does not match the URL; a 405 means the HTTP method handler is not exported.