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
Useapp/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.
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
GET /api/hello.
Try it with the dev server running:
HTTP methods
Export any standard HTTP method:ctx:
Dynamic parameters
Use brackets in the path, then read params from the route context:ctx.params:
Request parsing
JSON body
Form data
Query parameters
Headers and cookies
Streaming responses
Return aReadableStream for real-time data:
Chat endpoint
The most common API route pattern in Veryfront connects a chat UI to an agent: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 withcurl from another terminal while veryfront dev is
running:
404 means the file path does not match the URL; a 405 means the
HTTP method handler is not exported.