In this lesson, you ran every example in your reference, docs/api.md, against Niamh’s changed server, listed where the two now disagree, and sorted each of her changes into additive or breaking.
Key Points
- Passing tests don’t prove the docs. Niamh changed the server and updated the tests to match, and all seven pass. However, those tests check what Niamh expects, not what the reference tells Joon-ho.
- Check the reference the way a client would. Go through
docs/api.mdfrom the top. For each example, run itscurlcommand exactly as written, and compare what comes back with what the reference shows: the status line, the headers it lists, and the body. A match gets a tick. A difference goes on a list. GET /showsandGET /shows/6still answer200 OK, but the body doesn’t match. Where the reference hashost, the server sendspresenter, with the same name. The server also sendsgenre, a field the reference never mentions. The unknown id,99, still gets its404, as documented.- The reference’s own
POSTno longer works. Saturday Folk should get201 Created. It gets422, becausehostis an unrecognized key andpresenteris missing. The example withoutminutesstill gets422, but its details now namehostandpresentertoo. PATCH /shows/3answers204 No Content, with no body, where the reference promises200and the whole changed show. The change did happen, though: aGETon show 3 has the new start time. Only the answer changed.- The other examples all match: both
PATCHrequests to show 99, bothDELETErequests and the four error examples. Those need the last lesson’s setup:big.jsonfor the413, and for the500a damagedshows.jsonthat you restore from the backup straight after (see the commands below). - An additive change leaves everything a client already does working. Joon-ho’s page never sends
genre, and it doesn’t have to. APOSTwithpresenterand nogenrestill gets201 Created, because the field is optional. And their page reads only the fields it uses, so an extra one changes nothing. A client that rejected unknown fields would break, so the verdict is for Joon-ho’s page. - A breaking change stops something a client already does. After the rename, their
POSTgets422, and reading a show’shostgivesundefinedinstead of a name. After thePATCHchange, the show is still saved, but reading its empty answer withres.json()throwsSyntaxError: Unexpected end of JSON input. - The rule: a change is breaking when a request a client already sends, or the code that reads its answer, stops working. When everything that worked still works, it’s additive.
- What each change needs. An additive change only needs the reference updated:
genregoes into “The Show Object” and into thePOSTandPATCHbodies’ fields, as optional. A breaking change means Joon-ho’s page has to change too, so they need to hear first, or Niamh keeps the old behavior. - Public APIs plan for breaking changes. They announce breaking changes in a changelog, and can serve them as a new version, such as
/v2/shows, while the existing paths, such as/shows, keep the old answers for current clients.
Where the Reference and the Server Disagree
| Niamh’s change | Where the examples showed it | Additive or breaking |
|---|---|---|
host renamed to presenter, in answers and in request bodies |
GET /shows and GET /shows/6 send presenter, the POST /shows example gets 422 instead of 201, and the example without minutes gets 422 with different details |
Breaking: the reference’s POST gets 422, and a client reading host gets undefined |
A new field, genre, in every show |
GET /shows and GET /shows/6 |
Additive for Joon-ho’s page: a client never has to send it, because it’s optional (a POST without it gets 201), and a page that reads only the fields it uses sees nothing change |
PATCH /shows/:id answers 204 No Content with no body |
PATCH /shows/3 gets 204 instead of 200 and the show |
Breaking: the show is saved, but res.json() on the empty answer throws SyntaxError: Unexpected end of JSON input |