Step 3 — Backend: Express API

What This Step Is About

This step builds the core of the server: the Express application, its middleware stack, centralized error handling, and the metrics query logic. The goal is a well-structured, production-style API that you can reason about clearly and explain in depth during an interview.


Concepts and Tools

HTTP and REST

HTTP (HyperText Transfer Protocol) is the protocol that browsers and servers use to communicate. Every HTTP interaction is a request (from a client) and a response (from the server). Requests have a method (GET, POST, PUT, DELETE, PATCH), a URL path, optional headers, and an optional body.

REST (Representational State Transfer) is a convention for designing APIs around resources. A resource is a noun — a user, a repository, a commit. HTTP methods map to actions on that resource:

The :id syntax in a route is a route parameter — Express captures whatever is in that URL position as req.params.id.

Resources:

Express Middleware

Middleware is a function that runs between receiving a request and sending a response. In Express, middleware functions have the signature (req, res, next). Calling next() passes control to the next middleware in the chain.

Every request passes through the middleware stack in order. You can use middleware to: