0

I am looking for best practices on restful web service standards. One of the main things I want to sort out is entity separation in url. What is the right to do, group methods in one url or separate by entityname?

[WebGet(UriTemplate = "countries/{id}")]
Country GetCountry(int id);

[WebInvoke(UriTemplate = "countries/{id}", Method = "POST")]
Country CreateCountry(int id, Country country);
or 
[WebGet(UriTemplate = "resources/lists/countries/{id}")]
Country GetCountry(int id);

[WebInvoke(UriTemplate = "resources/lists/countries/{id}", Method = "POST")]
Country CreateCountry(int id, Country country);
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Yara
  • 4,441
  • 6
  • 42
  • 62

1 Answers1

1

The first option is cleaner. All URIs in a REST API should be resources so 'resources' isn't needed in the URI and I would say 'lists' isn't either since that's just a way of representing a collection of a resource.

Also, if you are going to be implementing REST services in C#, as per the example, I would highly recommend using ASP.NET Web API. It provides a very clean, powerful, and simple way of implementing REST services.

Restful Web Services is a great book that gives basic best practices around restful web service design and has great examples as well. You could also check out the Richardson Maturity Model which describes service restfulness in terms of levels of maturity. For a service to be restful it would have to be at the top maturity level, but the levels give a good guide for taking steps in the right direction.

johnlcox
  • 520
  • 6
  • 12