liveBook · Manning

MapGet

As explained in .NET in Action, Second Edition

MapGet is an ASP.NET Core endpoint-mapping method that associates HTTP GET requests with a handler.

MapGet associates a route with a handler in an ASP.NET Core web service. A root mapping such as app.MapGet("/", () => "Hello World!") returns the handler’s string response. section 3.1

A parameterized mapping adds request data to the handler:

  • The route "/{text}" captures the URL segment after the root. section 3.1
  • A handler parameter named text receives the captured value as a string. section 3.1
  • Route values are converted to the declared type; conversion failures or name mismatches fail the request. 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();

View the focused Program.cs example that maps both the root route and an ASCII-art route. section 3.1

How .NET in Action, Second Edition covers it

How deep it goes
Explains root and parameterized routes, typed parameters, name matching, and query strings; stops short of broader routing internals.
Examples
Uses root and ASCII-art routes, Figgle rendering, and an optional font query string.
What it assumes
Uses C# anonymous methods and typed parameters while demonstrating their role in a minimal web endpoint.
What you can do after
Build it from scratch by mapping routes to typed C# handlers and returning generated responses.
How it connects
Connects endpoint mapping with routing, anonymous methods, URL parameters, type conversion, query strings, and response generation.

Also explained in

Compare how 3 books explain MapGet →

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.