Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is a HTTP PUT request typically issued?

Tags:

I know HTTP PUT is an idempotent request that store something at a specific URI, according to the definition (quoted from the rfc)

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. 

But what is the definition of 'enclosed entity'? It doesn't seem possible for me to send form data (like for HTTP POST request) over. What about sending representation of the entity via JSON/XML or in other serialization formats?

In short, how does one send a HTTP PUT request over to store/update info at a specific URI then?

like image 913
Jeffrey04 Avatar asked Dec 18 '10 09:12

Jeffrey04


People also ask

How does an HTTP PUT request work?

PUT HTTP RequestThe PUT method requests that the enclosed entity be stored under the supplied URI. If the URI refers to an already existing resource, it is modified and if the URI does not point to an existing resource, then the server can create the resource with that URI.

What is the PUT method within HTTP?

The HTTP PUT request method is used to create a new resource or overwrite a representation of the target resource that is known by the client. Calling this method once is similar to calling it multiple times successively as it has the same effect. Though it is idempotent, we cannot cache its response.

Does HTTP PUT require a body?

If the request has a Content-Length header, then it has a body. It may be an empty body, but still a body. In contrast to a request with no Content-Length header, which has no body at all, not even an empty one. So yes, a PUT request, technically, strictly, has to have a body.


1 Answers

In REST you have:

GET - retrieve resource POST - create new resource PUT - update existing resource DELETE - delete resource 

So the PUT verb is used to update an existing resource on the server. Depending on the client there are various ways of sending a PUT request. For example with jquery AJAX:

$.ajax({     type: 'PUT',     url: '/products/123',     data: { name: 'new product name' } }); 
like image 103
Darin Dimitrov Avatar answered Sep 28 '22 08:09

Darin Dimitrov