Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't puts verbs in your URIs (eg /account/12345/<strong>transfer</strong>). URIs represent resources, not actions.</p> <p>The verbs to use are defined by the HTTP protocol (eg <code>GET</code>, <code>POST</code>, <code>PUT</code>, <code>OPTIONS</code>, <code>DELETE</code> etc). REST is a architecture design with a set of constraints, and HTTP is a protocol that adheres to these constraints. HTTP defines a limited set of verbs to transfer the state of a resource from client to server and vice versa. By definition you are constrained to these verbs only.</p> <p>The client should decide what HTTP verb to use based on what it is trying to do. The server doesn't need to tell it what verbs there are, it already knows based on the HTTP protocol.</p> <p>If the client needs to know what verbs it can use on a resource it can query the resource using the OPTIONS verb and look at <code>Allow</code> header in the response (assuming the server returns this information, which it should if it is being helpful). Some resources might only accept GET, while others may accept others such as POST and PUT.</p> <p>Have a look at the HTTP specification to see what verb to use in what context.</p> <p>To give an example from your original post. Say you have an account resource with a URI at</p> <pre><code>/accounts/12345 </code></pre> <p>and you want to close the account. Remember REST is <strong>state transfer</strong>. The client is closing the account so it has the account in a state of closed on its end. It then transfers that state to the server so that the client and server both are in line with each other. So you <code>PUT</code> the clients state (which is the resource in a closed state) onto the server</p> <pre><code>PUT /accounts/12345 </code></pre> <p>The body of the request should contain a representation of the resource in a closed state. Assuming you are using XML to represent the account resource it would be something like this</p> <pre><code>PUT /accounts/12345 &lt;?xml version="1.0"?&gt; &lt;account&gt; &lt;account_number&gt;12345&lt;/account_number&gt; &lt;balance currency="usd"&gt;100.00&lt;/balance&gt; &lt;state&gt;closed&lt;/state&gt; &lt;/account&gt; </code></pre> <p>The resource on the server now mirrors the resource on the client. Both are in a closed state. If you don't want to transfer the whole resource every time you make a change to one of its attributes you could split them out into a resource hierarchy. Make the status of the account its own resource and PUT to that to change it</p> <pre><code>PUT /accounts/12345/status &lt;?xml version="1.0"?&gt; &lt;state&gt;closed&lt;/state&gt; </code></pre>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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