Learn how to build, test, deploy, and maintain robust software systems.
The backend is the part of an application that runs on a server. When the frontend needs data or needs to perform an action, it sends a request over HTTP to the backend, which processes it, talks to a database or external service, and sends a response back. This lesson introduces the core ideas of backend development: what a server is, how HTTP requests and responses work, how routes map URLs to handlers, how middleware sits in the middle of every request, and how configuration and secrets should be managed safely. The examples use FastAPI (Python) and Express (Node.js) as representatives, but the concepts — routing, middleware, environment variables, error handling, and logging — are the same in every backend framework.
The client sends a request; the server processes it, may read or write data, and returns a response.
| Part | Meaning |
|---|---|
| Method | What action to perform (GET, POST, ...) |
| URL / path | Which resource or route |
| Headers | Metadata (content type, auth, ...) |
| Body | The data being sent |
| Status code | The result (200 OK, 404, ...) |
| Response body | The returned data |
A route maps an HTTP method and a path to a handler function. Different paths and methods run different handlers.
Middleware is code that runs before the route handler, for every request (or a group of them). It sits in the middle of the request pipeline.
A route handler should stay thin. Real logic belongs in a service layer, and data access belongs in its own layer. This separation keeps code testable and maintainable.
Configuration such as database URLs and API keys must not live in source code. They belong in environment variables (commonly loaded from a .env file) so they can differ between environments and stay out of version control.
| Environment | Purpose |
|---|---|
| Development | Local, with debug tooling |
| Staging | Mirrors production for testing |
| Production | Live, real users |
Handle errors centrally so failures return consistent responses. Log useful context (request, timestamp) but never secrets or sensitive user data.
The middleware runs before the route handler. Secrets and configuration come from environment variables, not the code.
Read a value from the environment with a fallback default.
(raises if DATABASE_URL is not set)
Each request passes through middleware before reaching the handler.
(the handler only runs after middleware passes)