Prompt file imported from Chugh3012/wardrobe (
.github/prompts/new-api-endpoint.prompt.md). Fill in{{route}},{{method}},{{description}}before use. Copyright stays with the author.
New API Endpoint
Create a new Azure Functions HTTP handler following project conventions.
Required Information
- Route: {{route}} (e.g.,
garments/:id) - Method: {{method}} (GET, POST, DELETE)
- Description: {{description}}
Steps
-
Create handler in
backend/src/functions/following the handler template:- Import
extractUserId,unauthorizedResponse,trackEvent,trackException - Auth check first
- Sequential input validation with descriptive 400 errors
- Call service layer in try/catch
- Generic 500 error message (log real error server-side)
- Register with
app.http()usingauthLevel: "anonymous"
- Import
-
Create/update service in
backend/src/services/:- Stateless exported functions
- JSDoc on public functions
- Use
.jsextensions on imports
-
Create/update model in
backend/src/models/if needed:- Pure TypeScript interface
- Export from
models/index.ts
-
Create tests in
backend/src/functions/<name>.test.ts:- Use test helpers from
testUtils.ts - Test: happy path, 401 (no auth), 400 (bad input), 404 (not found), 500 (server error)
- Use test helpers from
-
Add frontend API wrapper in
frontend/src/api.ts:- GET → use
cachedApiFetch - Mutation → use
apiFetch+invalidateCache
- GET → use
-
Run tests to verify everything passes