Products API (E-commerce Store (full stack))

You are building the backend of an online shop as a tiny HTTP API. Lines PRODUCT <id <price <stock <category <name… set up the catalog (prices like 19.99). Then each line is a request: <METHOD <path [json body]. Print <status <json with compact JSON and sorted keys. Money is always in cents (integers). GET /products → 200 {"products":[…]} (each {"category","id","name","price","stock"}, catalog order). GET /products/<id → 200 {"product":{…}} or 404 {"error":"product not found"}. Another method on /products → 405 {"error":"method not allowed"}; any other path 404 {"error":"not found"}; a line that is not a request 400 {"error":"bad request line"}.

Input: Catalog lines, then requests.

Output: One response per request.

Difficulty: Easy. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Turn the price into cents once, when you read the catalog.

More E-commerce Store (full stack) practice