Application code handles a request by running ordinary server-side logic inside a server process, using the request data supplied by the framework and producing a result that can become an HTTP response.
Learning Question
Once the route handler runs, what is actually happening inside the application?
At this point, the request has crossed the network boundary and reached server-side execution.
The handler is now ordinary code running in a process. It is no longer useful to imagine the request as moving through the internet. The relevant question becomes what this server-side code does with the request representation it received.
The first mental model is:
Request handling is local server-side execution caused by a received message.
Handler Code Runs Inside a Process
A route handler runs inside a server process or platform-managed runtime.
It uses CPU, memory, environment variables, open connections, libraries, and configuration available to that server-side environment.
For example:
app.post("/api/items", async (req, res) => {
const input = req.body;
const item = await createItem(input);
res.json(item);
});The browser does not run this function.
The server process runs it after framework dispatch.
Inside the handler, normal programming-language rules apply. Local functions are real local function calls. Variables are server-side runtime values. Exceptions or returned errors are server-side control flow until they are converted into response behavior.
Request Data Is Input, Not Authority
The request gives the server data.
It does not automatically give permission.
The handler or surrounding middleware must decide whether to trust, validate, and authorize that data.
Examples of request-derived data include:
- path parameters
- query parameters
- headers
- cookies
- bearer tokens
- JSON body fields
- uploaded files
All request-derived data is external input.
Even if it came from the application’s own frontend, the server should treat it as data received from outside the server trust boundary.
The user can modify client-side requests. Other clients can send requests without using the intended UI. Automated tools can send custom HTTP messages.
Therefore:
The server must decide what a request is allowed to do. The client does not grant itself authority by sending a request.
Typical Handler Work
A server-side handler may perform steps such as:
- Read request data.
- Validate shape and required fields.
- Authenticate the user or rely on authentication middleware.
- Authorize the requested operation.
- Transform input into domain-level values.
- Call application services or local helper functions.
- Query or update a database.
- Call external APIs.
- Decide the response status and body.
- Return or send a response.
Not every handler does all of these.
A simple static response may skip most of them. A complex business operation may involve many internal calls and external systems.
The request path explains how execution arrives at the handler; application design explains what the handler does after that.
Local Calls Inside the Server Are Real Function Calls
Inside the server process, application code can call other local functions directly.
For example:
handler(request)
-> validateInput(request.body)
-> createItem(input)
-> formatResponse(item)These are local calls if they happen in the same process and runtime.
This is different from:
browser
-> HTTP request
-> server handlerThe browser-to-server boundary uses messages. The handler-to-helper-function boundary may use ordinary function calls.
This distinction is one of the main reasons the phrase “the frontend calls the backend” is imprecise. The frontend sends a request. The backend may then call local server functions.
Server State Is Controlled by Server Code
The handler may read or change server-side state.
Examples include:
- in-memory caches
- session stores
- database records
- files
- queues
- logs
- metrics
- background jobs
The client does not access these directly merely by sending a request.
The server code chooses whether and how to use them.
For example, a request body may contain:
{"role":"admin"}That does not mean the user becomes an administrator. It is just input. Server-side authorization logic must decide whether that field is allowed, ignored, rejected, or interpreted.
Request Handling May Be Synchronous or Asynchronous
From the client’s point of view, a request is waiting for a response.
Inside the server, handling may involve synchronous or asynchronous work.
Examples:
- CPU work in the handler
- asynchronous database queries
- calls to external services
- waiting for file or network I/O
- scheduling background jobs
- streaming a response
The exact concurrency model depends on the server runtime.
A Node.js server, a threaded Java server, a Python ASGI server, a Go server, and a serverless function runtime can all expose HTTP handlers while using different execution models.
The durable point is:
The request maps to server-side work, but the runtime decides how that work is scheduled and executed.
Errors Become Response Behavior
Server-side errors do not automatically become useful client information.
An error may be:
- caught and converted into a
400,401,403,404, or500response - handled by framework error middleware
- logged internally while returning a generic message
- allowed to crash a worker or request context
- hidden from the client for security reasons
The client only receives what the server or infrastructure sends back as a response or connection failure.
The internal exception object does not cross the network as a live runtime object.
It may be serialized into response data, but only if the server chooses to do so.
What This Chapter Does Not Explain Yet
This chapter explains request handling as server-side execution.
It does not explain database protocols in depth.
It does not explain service-to-service networking in depth.
It does not explain how the response travels back through the transport layers.
Those are adjacent steps. The focus here is that once application code is invoked, the request is handled by ordinary server-side logic under server-side authority.
Core Mental Model
Keep these boundaries separate:
- The request supplies external input.
- The handler runs inside a server process.
- Local helper calls inside the server are ordinary function calls.
- Database calls and external API calls are separate operations initiated by server code.
- The server decides validation, authorization, side effects, and response shape.
- Runtime objects and exceptions do not cross the network unless serialized into response data.
The diagnostic question is:
Is this behavior caused by request data, or by server-side code deciding what to do with that data?
Final Summary
Application code handles a web request by running server-side logic inside a process after the request has been received, parsed, routed, and dispatched.
The client can send input, but the server controls how that input is validated, authorized, used, and converted into a response.