liveBook · Manning

MapGet

As explained in ASP.NET Core in Action, 3e

MapGet is an ASP.NET Core endpoint-mapping method for associating a URL pattern and handler with HTTP GET requests.

MapGet associates a URL path with a handler for HTTP GET requests. In a minimal API, the handler generates the response when a matching request arrives; GET should retrieve data without changing server state. section 3.6 section 5.2.2

Return a greeting from the root path

WebApplicationBuilder builder = WebApplication.CreateBuilder(args); WebApplication app = builder.Build(); app.MapGet("/", () => "Hello World!"); app.Run(); This endpoint returns plain text for GET requests to /. The server begins listening only after app.Run(). section 3.6

A MapGet call has two essential parts:

  • The first argument is the URL path, such as / or /person/{name}. section 3.6
  • The second argument is a delegate that produces the response, optionally using values captured from the route. section 3.6
  • Use MapPost or another Map* method when the operation creates, changes, or deletes data. section 5.2.2
Table 5.1 The minimal API map endpoints and the corresponding HTML verbs (view table figure)

Method

HTTP verb

Expected operation

MapGet(path, handler)

GET

Fetch data only; no modification of state. May be safe to cache.

MapPost(path, handler)

POST

Create a new resource.

MapPut(path, handler)

PUT

Create or replace an existing resource.

MapDelete(path, handler)

DELETE

Delete the given resource.

MapPatch(path, handler)

PATCH

Modify the given resource.

MapMethods(path, methods, handler)

Multiple verbs

Multiple operations.

Map(path, handler)

All verbs

Multiple operations.

MapFallback(handler)

All verbs

Useful for SPA fallback routes.

Compare MapGet with the other minimal API mapping methods and their expected HTTP operations. section 5.2.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines paths, handlers, route values, and GET semantics, but does not descend into middleware implementation.
Examples
Uses a root greeting endpoint and a person route that filters data by a name parameter.
What it assumes
Assumes basic C# delegates and HTTP terminology while defining paths, verbs, and request handling.
What you can do after
Apply MapGet to build minimal API endpoints that return responses for specific GET paths.
How it connects
Connects minimal APIs with endpoints, HTTP verbs, route parameters, delegates, and MapPost.

Also explained in

Compare how 3 books explain MapGet →

Related concepts

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