Implement CRUD API and tests
Company: Bnsf
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Take-home Project
You are given two software-engineering tasks.
1. Implement a simple REST API for a resource such as `Note` or `Message`.
- Support basic CRUD operations: create, read, update, and delete.
- The request body for create/update is **raw text**, not JSON, so the input `Content-Type` is `text/plain`.
- The API must return appropriate HTTP status codes and JSON responses.
- Handle common failure cases such as missing resources, invalid input, and unsupported media types.
A reasonable interpretation is:
- `POST /items` with `Content-Type: text/plain` creates a new item from the raw text body.
- `GET /items/{id}` returns the item if it exists.
- `PUT /items/{id}` with `Content-Type: text/plain` replaces the item's content.
- `DELETE /items/{id}` removes the item.
Even though requests use plain text, all responses should be JSON, for example:
- success: `{ "message": "created", "id": 1 }`
- error: `{ "message": "item not found" }`
2. Write unit tests for a function when you cannot see the original implementation code.
- You only have the function's specification or expected behavior.
- Your goal is to design tests that cover as many meaningful scenarios as possible, including edge cases and failure modes.
Explain what behaviors should be tested and how you would structure the tests to maximize confidence in correctness.
Quick Answer: This question evaluates proficiency in implementing RESTful CRUD APIs, correct HTTP semantics and content negotiation (text/plain request bodies with JSON responses), robust error handling, and the ability to design unit tests from a function specification to cover edge cases and failure modes.