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:
- Upload new parameters
- Get the latest parameters
- Get parameters for a given business date
- Make a set of parameters active
- Validate a set of parameters
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:
- POST where you include the parameter file in the post request
- GET of first URL
- GET of second URL
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
??
The activate and validate requirements are situations where you are attempting to change the state of a resource. It is no different that making an order "completed", or some other request "submitted". There are numerous ways to model these kinds of state change but one that I find that often works is to create collection resources for resources of the same state and then to move the resource between the collections to affect the state.
e.g. Create some resources such as,
If you want to make a set of parameters active, then add that set to the ActiveParameters collection. You could either pass the set of parameters as an entity body, or you could pass an url as a query parameter, as follows:
The same thing can be done with the /ValidatedParameters. If the Parameters are not valid then the server can return "Bad Request" to the request to add the parameters to collection of validated parameters.
In a REST environment, each URL is a unique resource. What are your resources? A financial calculator really doesn't have any obvious resources. You need to dig into what you are calling parameters and pull out the resources. For example, an amortization calendar for a loan might be a resource. The URL for the calendar might include start_date, term (in months or yers), period (when interest is compounded), interest rate, and initial principle. With all those values you have a specific calendar of payments:
Now, I don't know what you are calculating but your concept of a parameter list doesn't sound RESTful. As someone else said, your requirements above sound more XMLRPC. If you are trying for REST you need nouns. Calculations are not nouns, they are verb that act on nouns. You need to turn it around to pull the nouns out of your calcs.