It is possible in ASP.NET Core to handle a request directly, that is, to not route to a controller action. We define inline handlers by using an extension method that specifies the HTTP verb and the template to match, as follows:
- MapGet: HTTP Get
- MapPost: HTTP Post
- MapPut: HTTP Put
- MapDelete: HTTP Delete
- MapVerb: Any named HTTP verb; for example, Get is the same as using MapGet
There are actually two extension methods, MapXXX and MapXXXMiddleware, the first taking a delegate and the second a middleware class. An example follows.
These methods offer two possible signatures (except for Map<verb>, which takes the HTTP verb) and take the following parameters:
- pattern: This is a route template.
- requestHandler: This is a handler that takes the current context (HttpContext) and returns a task.
Here are two examples. In the...