liveBook · Manning

Routing

As explained in .NET in Action, Second Edition

A route is a URL pattern that an HTTP request can match to select an endpoint handler.

Routing maps HTTP requests to handlers. In ASP.NET Core, `MapGet` associates a URL pattern with a function that produces the response. A parameterized pattern such as `/{text}` binds part of the URL to a handler parameter; binding depends on the parameter name and type. section 3.1

Listing 3.5 Program.cs with ASCII art request handling
using Figgle;                              #1
  
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
 
app.MapGet("/", () => "Hello World!");
app.MapGet("/{text}",                      #2
  (string text) =>                         #3
  FiggleFonts.Standard.Render(text));      #4
  
app.Run();

See a minimal service mapping the root URL and a text parameter to responses. section 3.1

Render text from a route

A request to `/Testing%20123` matches `/{text}`; the handler receives the text and returns its ASCII-art rendering. section 3.1

How .NET in Action, Second Edition covers it

How deep it goes
Explains root and parameterized routes, including name matching, type conversion, and request failure when binding does not match.
Examples
Uses `/` for a greeting and `/{text}` to render URL text as ASCII art, with an optional font query parameter.
What you can do after
Apply routing through ASP.NET Core `MapGet` to return a greeting or render a path parameter as ASCII art.
How it connects
Connects URL routes to HTTP requests, endpoint handlers, C# anonymous methods, and optional query-string parameters.

Also explained in

Compare how 22 books explain routing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.