Add API Route
When the user invokes /add-api-route, follow these steps:
- •
Ask for the route name, HTTP method, path, and whether it's protected or public.
- •
Create shared schemas in
apps/shared/src/api-routes-schemas/[route-name]/index.ts:- •Request schema (query/body/params as needed)
- •Response schema
- •Follow naming:
[method][RouteName]RequestSchema,[method][RouteName]ResponseSchema
- •
Export schemas from
apps/shared/src/api-routes-schemas/index.ts - •
Create route definition at
apps/api/src/routes/[name]/[name].route.ts:- •Use
createRoute()from@hono/zod-openapi - •Import schemas from
shared/api-routes-schemas - •Add appropriate OpenAPI tag
- •Use
- •
Create route handler at
apps/api/src/routes/[name]/[name].index.ts:- •Use
new OpenAPIHono().openapi(route, handler) - •Export the router
- •Access context via
c.var(userData, db, services)
- •Use
- •
Register route in
apps/api/src/index.ts:- •Protected routes: AFTER
authMiddleware() - •Public routes: BEFORE
authMiddleware()
- •Protected routes: AFTER
- •
Verify: Run
pnpm typecheckto confirm no type errors.