Routing
Routing is how ASP.NET Core decides which piece of your code handles a given request — matching an HTTP method and a URL pattern to a handler.
Mapping routes
app.MapGet, app.MapPost, app.MapPut, and app.MapDelete each register a handler for one HTTP method and route pattern:
app.MapGet("/", () => "Welcome to the API");
app.MapGet("/status", () => "OK");
app.MapPost("/items", () => "Item created");
$ curl http://localhost:5225/status OK $ curl -X POST http://localhost:5225/items Item created
A request only matches if both the HTTP method and the path match exactly — a GET /items request would not hit the MapPost("/items", ...) handler above at all; it would fall through with a 404.
Route parameters
Curly braces in a route pattern capture part of the URL and pass it straight into the handler as a typed parameter:
app.MapGet("/hello/{name}", (string name) => $"Hello, {name}!");
app.MapGet("/products/{id:int}", (int id) => $"Product #{id}");
$ curl http://localhost:5225/hello/Priya Hello, Priya! $ curl http://localhost:5225/products/42 Product #42 $ curl http://localhost:5225/products/abc 404 Not Found
{id:int} adds a route constraint — ASP.NET only matches this route if the segment can actually parse as an int, which is why /products/abc falls through to a 404 instead of reaching the handler with a type error.
Query strings
Values after a ? in the URL don't need a route placeholder — bind them by matching a parameter name:
app.MapGet("/search", (string q) => $"Searching for: {q}");
$ curl "http://localhost:5225/search?q=laptops" Searching for: laptops