I’m working on a REST server. I have an order RESOURCE.
From my understanding the PUT verb should create a new order based on the URL. My question is: How can this work if the resource is new and you don’t know the ID of the new order?
I know the debate about POST vs PUT, but I’m quoting the w3 specs for PUT http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
“If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI”
In RESTful APIs,
PUTis typically used to update a resource or create one if it doesn’t exist at the specified URL (i.e. the client provides the id). If the server generates the id, RESTful APIs typically use aPOSTto create new resources. In the latter scenario, the generated id/url is usually returned or specified in a redirect.Example:
POST /orders/