go · level 2 check

a tuck shop JSON API.

Time to build a real web service! The school tuck shop wants an API, so apps can see the menu and order snacks. Your `Shop` keeps its stock in a map and counts every snack it sells. Its `Handle` method answers every request with JSON.

`GET /menu` lists each snack and how many are left, A to Z. `POST /orders` reads an order such as `{"snack":"crisps","qty":2}`, takes it out of the stock and answers 201 with a receipt. Bad JSON or a `qty` below 1 gets 400, an unknown snack gets 404 and the wrong method gets 405. A snack that has sold out gets 409, which means conflict.

Each line you type is one pretend request: a method, a path and, for an order, its JSON with no spaces. `main` sends it through `httptest` and prints the status and the reply, then the number of snacks sold. Fill in each `____`, run it, then try your own requests, such as `GET /menu`.

Fill in every ____ then run the checks.
  1. 1 It shows the menu from A to Zuses: maps and sorting
  2. 2 It takes an order and updates the stockuses: JSON
  3. 3 It says sorry when a snack sells outuses: wrapped errors
  4. 4 It turns away bad ordersuses: errors as values
  5. 5 It answers the wrong method or pageuses: routes and status codes
  6. 6 It counts every snack it sellsuses: pointer receivers

Take as long as you like and try as many times as you want.