← Over the wire · all materialsExercise 1 · 6 min · solo · 1–6 in class
Act 1 · HTTP

Read the wire

Before writing code against an API, you probe it. The client below talks to the Harbour Market API (the same code as the server in project/server/); its reference is in api.html. Write the requests yourself: method, path, headers, body. Answer the eight questions from what the server sends back.

Reading a response. The first line is the status. Then the headers, one per line. After the blank line, the body. The right-hand panel shows the same request written as fetch() and as curl.

  1. How many stalls does the market have?

    Two ways: count the array, or find the header that says it.
  2. What status code does GET /api/stalls/pizza answer?

  3. What is Mezcal Moon's average rating? Its id is mezcal.

  4. Which food stall is the cheapest? Let the server filter and sort.

    The query parameters are in api.html.
  5. POST a valid review for Taco Bike. Which status comes back?

    Valid: an author, a rating from 1 to 5, a text of 10–280 characters.
  6. Which response header holds the URL of the review you just created?

  7. Send the same POST without the Content-Type header. Which status?

  8. Which methods does /api/stalls allow? Ask it with a method it doesn't support, and read the headers.

    Comma-separated, e.g. PUT, PATCH.