The API behind it
The server the catalogue has been pretending to talk to. Five steps: a router with its middleware in the right order, one resource with all five verbs and honest status codes, a validator that refuses bad input before anything is written, a session, and the operational parts — one error handler, a log you can search, and health checks that tell the truth.
Builds on Node.js
What you end up with
- An Express app where the order of the middleware is the design, and an unknown path answers JSON.
- One resource, five verbs, paginated, with the status codes a client can act on.
- A validator that reports every problem at once and answers 422 rather than 500.
- Registration, login and a signed session, with the write routes guarded and the read routes public.
- One error handler, structured logs, a liveness check with no dependencies and a readiness check with them.
-
This console is a mock of Node in your browser —
require,expressand an HTTP layer behave like the real ones, and the checks send real requests to whatever you start. Everything you write here is what you would write for real.Not finished yet
-
One resource, addressed the same way by everyone: the path names the thing, the method says what to do to it, and the status code is the part a client reads first. A list endpoint that returns everything is a list endpoint that will one day return a million rows.
Not finished yet
-
Everything a client sends is input, and input is hostile until it has been checked. One function, used by all three writing routes, so the rules live in one place and a new rule is one line rather than three.
Not finished yet
-
Reading the catalogue is public. Changing it is not. The password is never stored, the token is signed rather than encrypted, and the failure message is identical whether the account exists or the password was wrong.
Not finished yet
-
The last step is the part nobody demos and everybody needs at three in the morning: one place where failures are turned into responses, a log you can search by field, and the two checks a platform calls to decide whether to send you traffic or restart you.
Not finished yet
Last step — finish it and the build is yours.
When it is finished