Request/response, routing, handlers, and middleware—how frameworks like Express, Django, Spring, and Gin structure a server.
Request/response, routing, handlers, and middleware—how frameworks like Express, Django, Spring, and Gin structure a server.
Lesson outline
A web framework turns HTTP requests into calls to your code and helps you return responses. Without one, you would parse the URL and request body by hand. Frameworks provide routing (URL + method → handler), middleware (auth, logging, CORS), and often validation, templating, and database integration.
Examples: Express (Node), Django / FastAPI (Python), Spring Boot (Java), Gin / Echo (Go). Concepts are similar; syntax differs.
You register routes: "when GET /users is requested, run this function." The function (handler) receives the request (URL, method, headers, body) and returns a response (status, body). The framework parses the URL and body (e.g. JSON) and may inject path params (e.g. /users/:id → id).
Example pattern: app.get("/users", listUsers); app.post("/users", createUser); app.get("/users/:id", getUser). The handler reads query params, validates body, calls the database or service layer, then returns res.json(data) or res.status(404).json({ error: "Not found" }).
Middleware runs before (or after) the handler. It can modify the request, run auth, log, or short-circuit (e.g. return 401 if not authenticated). Order matters: put auth before handlers that need it, CORS before everything. Common middleware: body parser (parse JSON into req.body), CORS (add CORS headers), auth (check token, set req.user).
In Express: app.use(cors()); app.use(express.json()); app.use(authMiddleware); app.get("/users", ...). In Django: middleware in MIDDLEWARE list. In Spring: Filter or HandlerInterceptor. Same idea everywhere.
The app reads config at startup: port, database URL, API keys. Use env vars (e.g. process.env.PORT, os.environ["DATABASE_URL"]) or a config file that is not committed. The framework starts an HTTP server that listens on a port and dispatches to your routes.
In development you often run with a hot-reload (e.g. nodemon, uvicorn --reload). In production you run one or more processes behind a reverse proxy or load balancer; the framework may support clustering or async workers.
Express: Minimal, lots of middleware, huge ecosystem; you assemble pieces. Django: Batteries-included (admin, ORM, auth); good for monoliths. FastAPI: Async, automatic OpenAPI, modern Python. Spring Boot: Enterprise-grade, dependency injection, many integrations. Gin/Echo: Fast, simple, great for APIs in Go. Pick one for your language and stick with it until you outgrow it.
Ready to see how this works in the cloud?
Switch to Career Paths for structured paths (e.g. Developer, DevOps) and provider-specific lessons.
View role-based pathsSign in to track your progress and mark lessons complete.
Questions? Discuss in the community or start a thread below.
Join DiscordSign in to start or join a thread.