Implement CRUD API and tests
Problem Description
You are presented with two distinct software engineering tasks.
Task 1: Implement a Simple REST API
Design and implement a basic RESTful API for a generic resource, such as a Note or Message.
- Core Functionality: The API must support standard Create, Read, Update, and Delete (CRUD) operations.
- Request Body Format: For
create(POST) andupdate(PUT) operations, the request body will be raw text, not JSON. TheContent-Typeheader for these requests must betext/plain. - Response Format: All API responses, regardless of success or failure, must be in JSON format and include appropriate HTTP status codes.
- Example success response:
{ "message": "created", "id": 1 } - Example error response:
{ "message": "item not found" }
- Example success response:
- Error Handling: The API should gracefully handle common failure scenarios, including but not limited to:
- Requests for non-existent resources.
- Invalid input (e.g., malformed IDs, empty content where not allowed).
- Unsupported media types in the
Content-Typeheader.
A reasonable interpretation of the API endpoints is as follows:
POST /items: Creates a new item using the raw text body from the request.GET /items/{id}: Retrieves the item corresponding to the given ID.PUT /items/{id}: Replaces the content of the item identified by the ID with the raw text body from the request.DELETE /items/{id}: Removes the item identified by the ID.
Task 2: Design Unit Tests for a Black-Box Function
For a given function where the internal implementation code is not visible, you are required to design a comprehensive set of unit tests.
- Context: You will only have access to the function's specification or its expected behavior.
- Objective: Your primary goal is to design tests that cover as many meaningful scenarios as possible, including various edge cases and anticipated failure modes.
- Deliverable: Explain in detail what specific behaviors should be tested and describe how you would structure these tests to maximize confidence in the function's correctness and robustness.
AI interview prep
Core dilemma
The central engineering conflict is demonstrating robust, production-ready API design and implementation for a simple CRUD service, while also showcasing a systematic and comprehensive approach to black-box testing. The specific 'raw text' input constraint for the API tests attention to detail in handling non-standard request formats and proper error propagation.
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 CRUD API and tests
Problem Description
You are presented with two distinct software engineering tasks.
Task 1: Implement a Simple REST API
Design and implement a basic RESTful API for a generic resource, such as a Note or Message.
- Core Functionality: The API must support standard Create, Read, Update, and Delete (CRUD) operations.
- Request Body Format: For
create(POST) andupdate(PUT) operations, the request body will be raw text, not JSON. TheContent-Typeheader for these requests must betext/plain. - Response Format: All API responses, regardless of success or failure, must be in JSON format and include appropriate HTTP status codes.
- Example success response:
{ "message": "created", "id": 1 } - Example error response:
{ "message": "item not found" }
- Example success response:
- Error Handling: The API should gracefully handle common failure scenarios, including but not limited to:
- Requests for non-existent resources.
- Invalid input (e.g., malformed IDs, empty content where not allowed).
- Unsupported media types in the
Content-Typeheader.
A reasonable interpretation of the API endpoints is as follows:
POST /items: Creates a new item using the raw text body from the request.GET /items/{id}: Retrieves the item corresponding to the given ID.PUT /items/{id}: Replaces the content of the item identified by the ID with the raw text body from the request.DELETE /items/{id}: Removes the item identified by the ID.
Task 2: Design Unit Tests for a Black-Box Function
For a given function where the internal implementation code is not visible, you are required to design a comprehensive set of unit tests.
- Context: You will only have access to the function's specification or its expected behavior.
- Objective: Your primary goal is to design tests that cover as many meaningful scenarios as possible, including various edge cases and anticipated failure modes.
- Deliverable: Explain in detail what specific behaviors should be tested and describe how you would structure these tests to maximize confidence in the function's correctness and robustness.