HTTP Request Methods – Get vs Put vs Post
#HTTP #Post #put #Get
HTTP Methods Explained
Now that we know what HTTP is and why it’s used, let’s talk about the different methods we have available to us.

In the weather app example above, we wanted to retrieve weather information about a city. But what if we wanted to submit weather information for a city?

In real life, you probably wouldn’t have permissions to alter someone else’s data, but let’s imagine that we are contributors to a community-run weather app. And in addition to getting the weather information from an API, members in that city could update this information to display more accurate data.

Or what if we wanted to add a new city altogether that, for some reason, doesn’t already exist in our database of cities? These are all different functions – retrieve data, update data, create new data – and there are HTTP methods for all of these.

HTTP POST request
We use POST to create a new resource. A POST request requires a body in which you define the data of the entity to be created.

A successful POST request would be a 200 response code. In our weather app, we could use a POST method to add weather data about a new city.

HTTP GET request
We use GET to read or retrieve a resource. A successful GET returns a response containing the information you requested.

In our weather app, we could use a GET to retrieve the current weather for a specific city.

HTTP PUT request
We use PUT to modify a resource. PUT updates the entire resource with data that is passed in the body payload. If there is no resource that matches the request, it will create a new resource.

In our weather app, we could use PUT to update all weather data about a specific city.
HTTP Request Methods – Get vs Put vs Post #HTTP #Post #put #Get HTTP Methods Explained Now that we know what HTTP is and why it’s used, let’s talk about the different methods we have available to us. In the weather app example above, we wanted to retrieve weather information about a city. But what if we wanted to submit weather information for a city? In real life, you probably wouldn’t have permissions to alter someone else’s data, but let’s imagine that we are contributors to a community-run weather app. And in addition to getting the weather information from an API, members in that city could update this information to display more accurate data. Or what if we wanted to add a new city altogether that, for some reason, doesn’t already exist in our database of cities? These are all different functions – retrieve data, update data, create new data – and there are HTTP methods for all of these. HTTP POST request We use POST to create a new resource. A POST request requires a body in which you define the data of the entity to be created. A successful POST request would be a 200 response code. In our weather app, we could use a POST method to add weather data about a new city. HTTP GET request We use GET to read or retrieve a resource. A successful GET returns a response containing the information you requested. In our weather app, we could use a GET to retrieve the current weather for a specific city. HTTP PUT request We use PUT to modify a resource. PUT updates the entire resource with data that is passed in the body payload. If there is no resource that matches the request, it will create a new resource. In our weather app, we could use PUT to update all weather data about a specific city.
8
0 Σχόλια 0 Μοιράστηκε