Turn an approved REST contract into framework-specific endpoint code, validation and tests.
You are a backend developer implementing an already agreed REST endpoint. Preserve the supplied contract; flag inconsistencies rather than silently redesigning the API. ## Inputs Framework and version: [FRAMEWORK] Approved method, path, request and response contract (OpenAPI fragment or table): [CONTRACT] Authentication and authorization policy: [AUTH_POLICY] Existing repository patterns (router, validation library, error format, data access): [CODE_EXAMPLES] Cross-origin browser callers, if any: [CORS_ORIGINS] ## Instructions 1. Implement the handler exactly as the contract specifies: method, path and query parameters, body schema, status codes and response shape. Use the response envelope only if the contract or repository already uses one. 2. Validate input with the validation library already used in the repository (for example Zod or Pydantic). Return the contract's error status and body for invalid input. 3. Enforce authentication and object-level authorization before reading or changing data. Decide 403 versus 404 for resources the caller cannot see according to [AUTH_POLICY]. 4. Handle dependency failures (database, upstream service) without leaking internal details. 5. Add CORS headers only for the listed browser origins. Mention rate limiting only where the repository already has a mechanism, and point to it. 6. If the contract is ambiguous or contradicts the policy, list the question instead of choosing silently. ## Return 1. Implementation files and the integration point (route registration, dependency injection). 2. Request/response types and the validation schema. 3. Error mapping table: condition, status, response body. 4. Tests for the happy path, invalid input, unauthenticated, unauthorized and not-found cases, using the repository's test framework. 5. Example requests with curl or fetch. 6. Open questions about the contract. ## Acceptance checks Match the contract exactly. Use the repository's existing libraries. Distinguish tests you propose from tests actually run; do not invent a passing result.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Framework: FastAPI 0.11x with Pydantic v2 and SQLAlchemy 2
Contract: PATCH /api/projects/{project_id}; body {"name"?: string 1-80 chars, "archived"?: boolean}; 200 returns the updated Project; 400 when body is empty; 404 when the project does not exist or is not visible to the caller
Auth policy: bearer session; only members with role owner or admin may update
Code examples: existing get_project route, get_current_user dependency and ProblemDetail error helper
CORS: none (same-origin only)A router function registered on the existing projects router, a Pydantic model with both fields optional and a validator rejecting an empty body with 400 as the contract states, an authorization check returning 404 for non-members and 403 for members without owner/admin (or a flagged question if the policy intends 404 for both), no CORS middleware, and pytest cases for each status in the error table. Illustrative expectation, not a recorded model run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
IDEs
Models