What is the purpose of HTTP PUT?

Why do we have the PUT method in AJAX and where is it most often used?

Example:

$.ajax({ url: 'script.php', type: 'PUT', success: function(response) { //... } }); 

Why didn't the author just use GET / POST?

+4
source share
1 answer

For the RESTful API, POST has a certain value (create a resource), while PUT has a different value (update an existing resource):

  • GET retrieves a list or item
  • PUT replaces a collection or item
  • POST creates a new item in the collection.
  • DELETE deletes a collection or item

However, if really β€œscript.php”, the one who developed it was not very careful when creating its API. "script.php" is pretty much not RESTful at all ... Usually the URL structure of the correct RESTful API looks like this. eg:

+15
source

Source: https://habr.com/ru/post/1502256/


All Articles