Routing & Handlers

How a method and a path become a function call, how precedence resolves ambiguity, and what a handler should and should not be responsible for.

How a Route Becomes a Function Call

A route table is a lookup structure over method and path; everything else about routing follows from which structure your framework chose.

Q · What happens between `POST /orders/42/items` arriving as bytes and your handler function being invoked?
Path Parameters

A path parameter is an attacker-supplied string that happens to be positioned where you expected an identifier.

Q · A path segment is a variable. What has to happen to it before a handler can use it?
Query Parameters

The least standardised part of an HTTP request, parsed differently by every stack, and the usual entry point for unbounded work.

Q · The query string has no schema and no agreed parsing rules. How do you accept one safely?
Route Precedence

When two routes can match one path, something decides which wins — and in half of all frameworks that something is the order of lines in a file.

Q · Two routes could match the same request. Which one runs, and did you choose that or inherit it?
Running Two API Versions in One Service

API Design decides the versioning policy; this is what the policy costs inside a running process, and how to pay it without forking the codebase.

Q · The contract has to change and old clients cannot be upgraded. How does one service serve two versions without becoming two services?
What a Handler Is Responsible For

A handler is an adapter between HTTP and one application operation — parse, resolve caller, call, map, return — and everything else it does belongs somewhere it can be reused and tested.

Q · What belongs inside a request handler, and what is it borrowing from layers that should own it?