liveBook · Manning

HTTP method

As explained in Pro ASP.NET Core 7, Tenth Edition

An HTTP method is a standardized operation name that specifies the type of operation requested from an HTTP server.

An HTTP method, also called an HTTP verb, specifies the type of operation a request asks a server to perform. In a RESTful web service, the method works with the URL: `/api/products/1` identifies a product, while the method says what to do with it. section 19.2.1

Table 19.3 HTTP methods and operations (view table figure)

HTTP Method

Description

GET

This method is used to retrieve one or more data objects.

POST

This method is used to create a new object.

PUT

This method is used to update an existing object.

PATCH

This method is used to update part of an existing object.

DELETE

This method is used to delete an object.

Use the method table when choosing a conventional operation: GET retrieves objects, POST creates one, PUT updates one, PATCH updates part of one, and DELETE removes one. section 19.2.1

In an ASP.NET Core minimal API, `MapGet` and `MapPost` can assign different handlers to routes under `/api/products`. GET `/api/products/1` retrieves one product; GET `/api/products` retrieves all products; POST `/api/products` reads a JSON request body and adds a product. Controllers can instead use attributes on action methods to declare which HTTP methods they accept. section 19.3 section 19.6

Send a POST request

Request the GET routes in a browser, then test creation with PowerShell: `Invoke-RestMethod http://localhost:5000/api/products -Method POST -Body (@{ Name="Swimming Goggles"; Price=12.75; CategoryId=1; SupplierId=1} | ConvertTo-Json) -ContentType "application/json"`. Entering the API URL in a browser does not send this POST request. section 19.3

Razor Pages also dispatch by method. An `OnGetAsync` handler can load a product for display; an `OnPostAsync` handler can accept a submitted price, update the product, and redirect. A form with `method="post"` and no action submits to its page URL. The example includes an anti-forgery field because POST requests without it are rejected. section 23.4.3

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines conventional method meanings and works through ASP.NET Core routing and form handlers, without examining HTTP protocol internals.
Examples
Uses product retrieval and creation routes, a PowerShell POST request, and a Razor Page that displays and edits a product.
What it assumes
Introduces the method-and-URL distinction while using an existing ASP.NET Core product application and database for implementation.
What you can do after
Apply it via ASP.NET Core to assign method-specific handlers and test GET and POST requests.
How it connects
Connects HTTP methods to RESTful APIs, URL routing, controller action attributes, Razor Pages handlers, JSON request bodies, and model binding.

Also explained in

Compare how 10 books explain HTTP method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.