How APIs work · Demo 4 of 4

A tiny API of your own

So far the browser only asked for data. An API can also change data. Add, edit and delete team members, and read the log: every click is one request with a verb that says what should happen.

1 The interface: the team

  • Loading…

Try adding someone with no name. The page does not stop you; the server does.

2 The request log: newest first

The four verbs

What to notice

  1. The address names the thing (/api/team/2). The verb names the action.
  2. POST and PUT carry a body: the data being sent to the server.
  3. The data lives on the server. Open this page in a second tab and reload the list: same team.
  4. The server checks what it receives. A bad request gets 400 and a reason.

The whole API is one short file. Read server.js ↗

Explain it back

  • Which requests had a body? Which did not? Why?
  • Who decided the new person's id: the page or the server?
  • What came back when you added someone with no name?
  • Design the confirmation for “Delete”. What happens if the server says 404?