Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, a GET request will return a resource serialised into a defined format, and metadata about that resource (which together constitute a representation of the resource). When you PUT a representation back, it does not need to contain the metadata, nor does it need to be in the same format as the original (or any subsequent) GET request. The server will then update the resource based on the representation you provided.</p> <p>An example from HTML is the <code>&lt;head&gt;</code> and <code>&lt;body&gt;</code> elements, which provide metadata about the resource, and the resource representation; and the <code>text/html</code> and <code>application/x-www-form-urlencoded</code> content types, which transfer resource representations in two different formats, the former with metadata, the latter without. When you GET the resource after POSTing to it, you don't expect to receive <code>application/x-www-form-urlencoded</code>-formatted data!</p> <p>I am not sure what you mean by "REST variant". There is only one REST. If you are referring to other HTTP-based APIs, please don't call them REST. For further details on API styles, see <a href="http://nordsc.com/ext/classification_of_http_based_apis.html" rel="nofollow">Classification of HTTP-based APIs</a>.</p> <p>Lastly, you ask for examples of non-leaf PUT requests. I am not sure exactly what you mean by non-leaf, as I can think of two types:</p> <ol> <li>Collections</li> <li>Sub-resources</li> </ol> <p><strong>Collections</strong> Lets say you have a car catalogue, available at <code>/cars</code>. If you decided you wanted to erase all your cars, you could either do <code>DELETE /cars/1</code>, <code>DELETE /cars/2</code> ... etc. or you might choose <code>PUT /cars</code> with an empty body or an array with no contents. The latter would obviously be a lot more efficient.</p> <p><strong>Sub-resources</strong> Continuing this theme, lets say that there is a car, <code>/cars/1</code> which is represented thus:</p> <pre><code>{ "model":"Model-T", "mfgr":"Ford", "colour":"black" } </code></pre> <p>Now, you may wish to allow these fields to be accessed by URLs such as <code>/cars/1/mfgr</code> which would return <code>Ford</code> or perhaps <code>{"mfgr":"Ford"}</code>. Now the URL <code>/cars/1</code> represents a non-leaf resource. However there is still no problem in PUTting a new representation to the URL. This would therefore update the sub-resource URLs' values too.</p> <p>Lastly, you may want to take a look at the <a href="http://stateless.co/hal_specification.html" rel="nofollow">HAL</a> format for transmitting hypertext via JSON.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload