PUT Method
In this lesson, we will learn about the HTTP PUT request method.
What is the PUT method?
The HTTP
PUT
method will update an existing resource or create a new resource on the server, depending on the request payload.
PUT
is idempotent.: This means that an outcome will remain the same even if it’s called several times successively. For instance, calling the POST several times with the same request data may create a new resource each time, therefore, it is not idempotent.
Now, let’s understand more what this means with the example below.
-
Let’s make a
GET
request for the givenURL
and fetch an existing recordcurl -X GET https://jsonplaceholder.typicode.com/posts/1
-
Update this record’s title using
PUT
requestcurl -X PUT -d '{"title":"This is an updated post"}' https://jsonplaceholder.typicode.com/posts/1
- In the
PUT
request above, (-X
is forHTTP Method
and-d
for--data
). The data is passed in the form of aJSON
string
Get hands-on with 1400+ tech skills courses.