Sobes.tech
Junior — Middle

In what cases should the HTTP PUT method be used?

sobes.tech AI

Answer from AI

The HTTP PUT method is used to create or replace a resource at a specified URI. It is applied when you need to completely update an existing resource or create a new one if it does not exist. Unlike POST, PUT is idempotent — repeated requests with the same data will not change the result.

Example of using PUT:

  • Updating a user profile at /users/123 with new data.
  • Uploading a file to the server with a specific name, where each PUT overwrites the file.
PUT /users/123 HTTP/1.1
Content-Type: application/json

{
  "name": "Ivan",
  "email": "ivan@example.com"
}