POST is an HTTP method for sending new data to a server to add or process. Unlike GET, which retrieves data, POST can add a product to a list. section 8.2
Adding a product
A form sends a product’s name and price to /products using POST. A Spring controller receives the values, creates a Product, and asks a service to add it. The controller then returns the updated product list to the view. GET and POST can use the same path because the HTTP method distinguishes their actions. section 8.2
Table 8.2 Basic HTTP methods you’ll often encounter in web apps
|
HTTP method
|
Description
|
|
GET
|
The client’s request only retrieves data.
|
|
POST
|
The client’s request sends new data to be added by the
server.
|
|
PUT
|
The client’s request changes a data record on the server
side.
|
|
PATCH
|
The client’s request partially changes a data record on
the server side.
|
|
DELETE
|
The client’s request deletes data on the server side.
|
Compare POST with GET, PUT, PATCH, and DELETE to see how HTTP methods express different request actions. section 8.2
