Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would use the same URL.</p> <p>POST to <code>customer/21/credits</code> with a POST variable called <em>extraCredit</em> set to <em>5</em>. POST is supposed to be used for <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5" rel="nofollow noreferrer">annotation of existing resources</a> (or creating subordinate resources). There is no reason why you should need a new URL.</p> <p>If an individual credit is a resource in your system that deserves its own URL, then the response URL from POSTing to <code>customer/21/credits</code> should include the URL of the new credit resource e.g. <code>customer/21/credit/12</code>.</p> <p>You could define an XML representation of credits to POST to <code>customer/21/credits</code>, but I would not consider it worthwhile in this simple example. REST payloads do not have to be XML.</p> <p>A URL like <code>customer/21/addedCredits?amount=5</code> doesn't make sense to me because it doesn't really identify a resource. If someone issues a GET to <code>customer/21/addedCredits?amount=5</code> what would you return to them?</p> <p>The one thing you should definitely <strong>not</strong> do is change the state of the customer resource when someone GETs a URL like <code>customer/21/addedCredits?amount=5</code>. Since the title of your question acknowledges that you will need to use POST your probably realise this. GET is supposed to be <em>safe</em>, which means that issuing a GET shouldn't change a resource's state.</p>
 

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