Mô phỏng một router xử lý đủ các method trên tài nguyên product (gồm name, price):
POST <name> <price> → 201 kèm itemGET <id> → 200 kèm item / 404PUT <id> <name> <price> → 200 / 404PATCH <id> price <price> → 200 / 404DELETE <id> → 204 / 404LIST → 200 kèm mảng item (id tăng dần, bỏ qua đã xóa)Input:
POST a 10
PATCH 1 price 12
GET 1
DELETE 1
LIST
Output:
{"status":201,"item":{"id":1,"name":"a","price":10}}
{"status":200,"item":{"id":1,"name":"a","price":12}}
{"status":200,"item":{"id":1,"name":"a","price":12}}
{"status":204}
{"status":200,"items":[]}
Mỗi dòng là một lệnh trong tập POST/GET/PUT/PATCH/DELETE/LIST như mô tả.
price là số nguyên. Số lệnh ≤ 500.
In response JSON đúng cho từng method; item luôn theo thứ tự key id,name,price. LIST in {"status":200,"items":[...]}.
Ví dụ:
Đầu vào:
POST a 10
PATCH 1 price 12
GET 1
DELETE 1
LIST
Đầu ra:
{"status":201,"item":{"id":1,"name":"a","price":10}}
{"status":200,"item":{"id":1,"name":"a","price":12}}
{"status":200,"item":{"id":1,"name":"a","price":12}}
{"status":204}
{"status":200,"items":[]}Giải thích:
Đang tải editor...