PUT Method

In this lesson, we will learn about the HTTP PUT request method.

We'll cover the following

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.

  1. Let’s make a GET request for the given URL and fetch an existing record

    curl -X GET  https://jsonplaceholder.typicode.com/posts/1
    
  2. Update this record’s title using PUT request

    curl -X PUT -d '{"title":"This is an updated post"}'  https://jsonplaceholder.typicode.com/posts/1
    
  • In the PUT request above, ( -X is for HTTP Method and -d for --data). The data is passed in the form of a JSON string

Get hands-on with 1200+ tech skills courses.