I'm struggling to determine how to design restful URLs. I'm all for the restful approach of using URLs with nouns and not verbs don't understand how to do this.
We are creating a service to implement a financial calculator. The calculator takes a bunch of parameters that we will upload via a CSV file. The use cases would involve:
I gather the restful approach would be to have the following type URLs:
/parameters
/parameters/12-23-2009
You could achieve the first three use cases with:
But how do you do the 4th and 5th use case without a verb? Wouldn't you need URLs like:
/parameters/ID/activate
/parameters/ID/validate
??
General principles for good URI design:
/resource
or /resource/
; create 301 redirects from the one you don't use(Note: I did not say "RESTful URI design"; URIs are essentially opaque in REST.)
General principles for HTTP method choice:
General principles of web service design with HTTP:
201 Created
after creating a resource; resource must exist at the time the response is sent202 Accepted
after performing an operation successfully or creating a resource asynchronously400 Bad Request
when someone does an operation on data that's clearly bogus; for your application this could be a validation error; generally reserve 500 for uncaught exceptions401 Unauthorized
when someone accesses your API either without supplying a necessary Authorization
header or when the credentials within the Authorization
are invalid; don't use this response code if you aren't expecting credentials via an Authorization
header.403 Forbidden
when someone accesses your API in a way that might be malicious or if they aren't authorized405 Method Not Allowed
when someone uses POST when they should have used PUT, etc413 Request Entity Too Large
when someone attempts to send you an unacceptably large file418 I'm a teapot
when attempting to brew coffee with a teapotETag
headers are good when you can easily reduce a resource to a hash valueLast-Modified
should indicate to you that keeping around a timestamp of when resources are updated is a good ideaCache-Control
and Expires
should be given sensible valuesIf-None-Modified
, If-Modified-Since
)With regard to your specific question, POST should be used for #4 and #5. These operations fall under the "RPC-like" guideline above. For #5, remember that POST does not necessarily have to use Content-Type: application/x-www-form-urlencoded
. This could just as easily be a JSON or CSV payload.