Thursday, October 4, 2012

REST URL - A best practise/standard for discussion

REST a most used approach for calling the services from front end Rich HTML5 pages. Going around I was not able to find a standard that is defined for constructing the REST URL....

Thinking around and google, I though I could share the approach that I have in my mind....

One the practise that we could use for constructing the REST URL can be:


* <context_URL>/[Noun Plural] - To represent the REST URL that return a collection of object like Customers, Users etc..,. Example /Customers  or /Users etc..,
* <context_URL>/[Noun]/[Noun Specific] - To represent the REST URL that return a Specific Object of a Noun, example like - Customer/<id> where <id> could be any ID of the customer

Example: /cutomer/1234 - to represent a specific customer detail

* <context_URL>/Noun Plural]/[Noun Specific]/<Related Noun Collections> - To represent the collection of Objects that are related to a specific noun.

Example : /customer/1234/orders - to indicate all the orders of the customer with ID 1234

* <context_URL>//Noun Plural]/[Noun Specific]/<Related Noun>/<Related Noun ID>  To represent a specific Object that is related with the parent noun.

example : /customer/1234/order/o1234

In my opinion , following this way of constructing a REST Url could be more readable and easy to follow and call by clients...


 Some Sample URL based on the above pattern:


/customers -  returns a collections of customer ID/info as per implementation
/customer/<id> - returns information of the specific customer with id  passed in <ID>
/customer/<id>/addresses - returns all the address information of the customer
/customer/<id>/orders -  returns all the order id of the customer
/customer/<id>/order/o123 -  returns the order information of the related customer with ID specified in <id>


Please feel free to leave your suggestions and thoughts...