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

Building REST APIs With Express (Summary)

You’ve finished the course. You can now design a REST API’s resources and routes, and build it with Express 5: create, read, update and delete through route parameters and query strings, with the data saved safely to a JSON file.

Dev’s Desk, Request by Request

The ticket desk that replaced Dev’s clipboard answers every request the same way. Express finds the first route that matches, and your handler answers once, with the status you chose. Here’s how the finished desk answers the requests the course built it for:

Request Answer
GET /tickets?status=waiting&category=electrical 200 OK and a page with Priya’s toaster only
GET /tickets/99 404 Not Found, code ticket_not_found
POST /tickets with Rosa’s radio 201 Created with a Location header
PATCH /tickets/1 with {"status":"on-bench"} 200 OK, Priya’s toaster on the bench
PATCH /tickets/4 with {"status":"waiting"}, Joe’s fixed stool 409 Conflict, code ticket_closed
DELETE /tickets/<id>, Rosa’s radio 204 No Content
GET /volunteers?speciality=bikes 200 OK and a page with Lucía only

Each resource has its own router. The tickets router is mounted at /tickets and the volunteers router at /volunteers, so each router’s paths are relative to its mount path.

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 the course. You can now design a REST API’s resources and routes, and build it with Express 5: create, read, update and delete through route parameters and query strings, with the data saved safely to a JSON file.

00:16 Here’s Dev’s ticket desk: Express finds the first route that matches, and your handler answers once, with the status you chose. Which electrical tickets are waiting?

00:27 Only Priya’s toaster. Ticket 99 gets a 404. Rosa’s radio gets a 201, with a Location header. Priya’s toaster goes on the bench. Joe’s stool is already fixed, so moving it back to waiting gets a 409.

00:43 Deleting Rosa’s radio gets a 204. The volunteers have their own router too. Who fixes bikes? Lucía.

00:53 Every change stays in the tickets file, even if the app crashes mid-save. Hana’s kettle and Omar’s fan arrive together. The store changes each in memory, puts every save in line, and writes a temporary file renamed over the real one.

01:08 Both get a 201, and the file holds seven tickets, Dev’s five plus these two.

01:16 Paths name things, and the method says what to do. Every request gets one response, with the status you chose. Route parameters are strings. A query value may also be an array or missing, so check it.

01:30 A router’s paths are relative to its mount path. Make each change with no await between reading and writing, and queue every save.

01:40 You checked each request body by hand, and a missing field got a 422. Next on the path, schemas take over those checks. That’s all you need about schemas for now.

01:53 Thanks for building Dev’s ticket desk.

Become a Member to join the conversation.