Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Testing, Documenting and Building a Node API (Summary)

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:

Language: Shell
$ 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.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 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, and build a complete REST API from a brief, without a walkthrough.

00:21 First, the tests. 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.

00:34 The request line’s suite passes all 25 tests.

00:40 Next, the docs. Your reference gives each endpoint’s method, path and every response. Its examples run as tests too, so a test fails when the server stops matching one.

00:52 You still check the rest of the reference by hand. Last, Gloria’s brief gave you the rules and the checks, not the steps. When Amara, a listener, asks twice for the same show, her second request gets a 409 Conflict.

01:10 Then you explained your request line to the mentor, and pitched an API of your own.

01:17 Test through HTTP, the way clients call your API. Give every test its own server and its own data file. Test the error paths as carefully as the happy path.

01:29 Write the reference before the code, and run its examples as tests. Build one resource at a time, with its tests as you go.

01:40 This course ends the Node Servers and REST APIs path. Databases, logins and putting an API online come later. Until then, keep building the API you pitched, one endpoint at a time.

01:55 Thanks for building Gloria’s request line.

Become a Member to join the conversation.