Description
The API currently supports GET /items (list all), POST /items (create), PATCH /items/:id (update), and DELETE /items/:id (delete) — but there is no way to retrieve a single item by its ID.
Adding GET /items/:id is a standard REST convention and would allow clients to fetch details of a specific todo item without downloading the entire list.
Use Case
- A client that only needs to display or verify one item shouldn't have to fetch all items and filter client-side.
- Follows RESTful resource design where every resource has its own URI.
- Useful for confirming an item's state after a PATCH operation or for deep-linking.
Proposed Implementation
@app.route("/items/<int:item_id>", methods=["GET"])
def get_item(item_id):
items = _get_items()
item = next((i for i in items if i["id"] == item_id), None)
if item is None:
return jsonify(error="item not found"), 404
return jsonify(item)
Proposed Tests
def test_get_item(client):
client.post("/items", json={"name": "My Task"})
resp = client.get("/items/1")
assert resp.status_code == 200
data = resp.get_json()
assert data["name"] == "My Task"
assert data["id"] == 1
def test_get_item_not_found(client):
resp = client.get("/items/999")
assert resp.status_code == 404
Acceptance Criteria
Description
The API currently supports
GET /items(list all),POST /items(create),PATCH /items/:id(update), andDELETE /items/:id(delete) — but there is no way to retrieve a single item by its ID.Adding
GET /items/:idis a standard REST convention and would allow clients to fetch details of a specific todo item without downloading the entire list.Use Case
Proposed Implementation
Proposed Tests
Acceptance Criteria
GET /items/:idreturns the item as JSON with status 200{"error": "item not found"}if the ID doesn't exist