How is a HTTP PUT request typically issued?

Jeffrey04 picture Jeffrey04 · Dec 18, 2010 · Viewed 85k times · Source

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?

Answer

Darin Dimitrov picture Darin Dimitrov · Dec 18, 2010

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' }
});