Implement Update and Delete Endpoints in a FastAPI CRUD Service
Context
You are given a FastAPI project that already has working Create and Read endpoints and shared Pydantic models for request/response. Extend the service to complete CRUD by adding Update and Delete endpoints that are consistent with the existing code style and API contracts.
Assumptions (adjust to match the actual project):
- The resource is an "Item" stored in memory or a repository abstraction.
- Existing endpoints follow typical REST conventions:
POST /items→201 Createdwith response body of the created item.GET /items/{item_id}→200 OKwith item body, or404 Not Foundif not found.
- The same Pydantic models are reused across endpoints (e.g.,
ItemCreate,ItemUpdate,ItemRead).
Requirements
- Implement Update and Delete endpoints that match existing request/response schemas and status codes.
- Preserve idempotency where applicable and return
404 Not Foundvs204 No Contentappropriately. - Validate inputs and handle exceptions cleanly (e.g.,
422 Unprocessable Entityfor invalid input,404 Not Foundfor not found). - Write unit tests covering all four endpoints (Create, Read, Update, Delete), including success and error paths.
- Explain how you would approach this if you have never used FastAPI before, leveraging existing endpoints as templates and the FastAPI documentation.
AI interview prep
Core dilemma
Achieving robust, consistent, and idiomatic RESTful API behavior within a specific framework while managing state and ensuring testability.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Update and Delete Endpoints in a FastAPI CRUD Service
Context
You are given a FastAPI project that already has working Create and Read endpoints and shared Pydantic models for request/response. Extend the service to complete CRUD by adding Update and Delete endpoints that are consistent with the existing code style and API contracts.
Assumptions (adjust to match the actual project):
- The resource is an "Item" stored in memory or a repository abstraction.
- Existing endpoints follow typical REST conventions:
POST /items→201 Createdwith response body of the created item.GET /items/{item_id}→200 OKwith item body, or404 Not Foundif not found.
- The same Pydantic models are reused across endpoints (e.g.,
ItemCreate,ItemUpdate,ItemRead).
Requirements
- Implement Update and Delete endpoints that match existing request/response schemas and status codes.
- Preserve idempotency where applicable and return
404 Not Foundvs204 No Contentappropriately. - Validate inputs and handle exceptions cleanly (e.g.,
422 Unprocessable Entityfor invalid input,404 Not Foundfor not found). - Write unit tests covering all four endpoints (Create, Read, Update, Delete), including success and error paths.
- Explain how you would approach this if you have never used FastAPI before, leveraging existing endpoints as templates and the FastAPI documentation.