0

For start - I understand the difference between GET and POST.

What I don't understand is how does a request that doesn't mention either of them work, when and why would I want to use it?

Here's an example from ASP.NET Docs:

Map method

MapGet method

MapPost method

2
  • The docs you listed are for creating routes for an HTTP server, not a client like it seems you think. These methods don't send a request, they receive them. As such, Map matches all requests regardless of request type, MapGet matches all requests of GET type, etc.
    – iced
    Sep 19, 2022 at 20:44
  • @iced " These methods don't send a request, they receive them." - This definitely makes more sense if you think of it this way, thanks. (Can't sent a request that is both GET and POST, but can receive both GET and POST requests)
    – lukkasz323
    Sep 19, 2022 at 21:03

1 Answer 1

0

HTTP requests always have an HTTP method associated with them. GET and POST are two such methods, but there are others (see here).

When you call the MapGet, MapPost, or Map methods, you are creating "rules" that ASP.NET will use to route incoming requests to different parts of your application code, depending on which rules are matched.

Part of each rule is the route pattern itself, but you can also require a specific HTTP method in order for a rule to be matched. That's what MapGet and MapPost are doing - when you use them, they will only match requests that also have the appropriate HTTP method (GET and POST, respectively). In contrast, Map will match any incoming request (that also matches the route pattern), regardless of the HTTP method of the request.

This can be an easy way to get your application to behave differently depending on the HTTP method that is used. For example, you could use MapGet to route GET requests to a method that will return something, while using MapPost to route POST requests to a method that will create a new record. If you want your application to behave the same way for all requests (or you want to programmatically check the request method), you could just use Map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.