| title | API action |
|---|
API action (endpoint) — is an HTTP handler that performs database updates and other logic required by the business logic.
Endpoints reside in the /endpoints folder within a resource.
Each endpoint is a single file with a meaningful name, e.x. list, create, update, remove.
Each endpoint file must default-export a createEndpoint({...}) call. Routes are auto-discovered — no manual registration needed.
If schema is provided, the validate middleware auto-applies. Validated data is available on ctx.validatedData.
import { z } from 'zod';
import createEndpoint from 'routes/createEndpoint';
import { companyService } from 'resources/companies';
const schema = z.object({
userId: z.string(),
});
export default createEndpoint({
method: 'get',
path: '/',
schema,
async handler(ctx) {
const { userId } = ctx.validatedData;
const companies = await companyService.find({ userId });
return companies; // returned value becomes ctx.body
},
});