Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use PUT methods? [duplicate]

Tags:

http

post

put

There does not seem to be any advantage over using POST. Is there a specific scenario where PUT works better/ faster/ more securely/ something else? Why would anyone code for a whole new http method when you can do everything with basically the same amount of work using a POST?

like image 222
Jeremy Holovacs Avatar asked May 20 '13 20:05

Jeremy Holovacs


People also ask

Why we use PUT method instead of POST?

Use PUT when you want to modify a single resource which is already a part of resources collection. PUT overwrites the resource in its entirety. Use PATCH if request updates part of the resource. Use POST when you want to add a child resource under resources collection.

Is Put method vulnerability?

The PUT method is particularly dangerous. If the attacker uploads arbitrary files within the web root, the first target is to create a backdoor script on the server that will be executed by a server-side module, thereby giving the attacker full control of the application, and often the web server itself.

Which is better put or patch?

When a client needs to replace an existing Resource entirely, they can use PUT. When they're doing a partial update, they can use HTTP PATCH. For instance, when updating a single field of the Resource, sending the complete Resource representation can be cumbersome and uses a lot of unnecessary bandwidth.

Is put idempotent?

The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), whereas successive identical POST requests may have additional effects, akin to placing an order several times.


1 Answers

FROM RFC2616:

The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource.

like image 110
Ahmed Masud Avatar answered Nov 15 '22 00:11

Ahmed Masud