Add an API Endpoint
How to add a new endpoint to an existing module.
1. Edit the Module Spec
Open the module's OpenAPI spec (e.g., apps/api/internal/modules/recipe/transport/api/openapi.yaml) and add the new path or operation:
paths:
/recipes:
get: ... # existing
post: # new
operationId: createRecipe
summary: Create a recipe
tags: [Recipes]
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CreateRecipeRequest"
responses:
"201":
description: Created
content:
application/json:
schema:
$ref: "#/components/schemas/Recipe"
Add any new schemas under components/schemas in the same file.
2. Run Generate
pnpm generate --filter=api
This bundles all module specs and regenerates server code.
3. Implement the Handler
The build will fail because Server no longer satisfies the generated ServerInterface. Add the missing method in transport/api/handler.go:
func (s *Server) CreateRecipe(w http.ResponseWriter, r *http.Request) {
// implementation
}
4. Verify
go build ./...