You’ve finished Testing, Documenting and Building a Node API. Gloria’s request line now takes song requests for her Sunday show. You can now:
- Test an Express API through real HTTP requests
- Document every endpoint
- Build a complete REST API from a brief, without a walkthrough
Each test starts its own API on port 0, with a fresh data file. It sends real requests with fetch(), and checks the status, the headers and the body. The request line’s suite passes all 25 tests, shown here without the test lines and request logs above the summary:
$ npm test
...
ℹ tests 25
ℹ suites 0
ℹ pass 25
ℹ fail 0
...
Your reference in docs/api.md gives each endpoint’s method, path and every response, errors included. The shared errors, such as 415 for a body that isn’t sent as JSON, appear once in its Errors table.
Its examples, kept as data in docs/examples.ts, run as tests too, so a test fails when the server stops matching one. You still check the rest of the reference by hand, and keep it in step with examples.ts.