views:

67

answers:

2

Historically operating system directory-structures have been trees:

  • C:
    • Windows
      • System32
    • Program Files
      • Common Files
      • Internet Explorer

And the REST architecture emulates the same thing:

But, looking the current structure, I need to make searches:

  • All pictures that are not from Finland?
  • All pictures taken in 2005?
  • All pictures in timeline?

It is not efficient to do a REST-interface with every tree-hierarchy combinations. You need more efficient information management; you need an attribute-system rather than a tree-structure. (Oh, why the operating systems are not based on attributes?)

StackOverflow and Google seem to use attributes and syntax with "+"-marks like:

Today's frameworks like WCF and ASP.NET MVC have a good support for RESTful tree-structures. But is there support for attribute-structures? Wouldn't you call an attribute-structure still REST?

I would like to make an attribute-WebService and use it with a LINQ in Silverlight-client... Which is the best way to start? :-)

+3  A: 

In order to create an effective REST interface you need to identify the resources that make sense for your client application. If you look at you use cases:

All pictures that are not from Finland? All pictures taken in 2005? All pictures in timeline?

The question you need to answer, is if this requires three resources or just one. I am assuming you want to have more than just these three queries, so therefore the most flexible solution is to define a generic resource which is a "collection of pictures".

/Thomas/pictures

From here, you want to be able limit contents of this resource by using query parameters.

/Thomas/pictures?country=not-finland
/Thomas/pictures?year=2005

In the case of the third item it may make sense to create a separate resource for that item.

/Thomas/PictureTimeline

There are other scenarios where it may make sense to create additional resource such as

/Thomas/FavouritePictures

The important thing is to identify what key concepts of your application you want to model as resources and then assign those resources an URL. Trying to do REST design via the URL space is going to make you bang your head against the wall.

Darrel Miller
Yep - that is more to the point (+1). Should take a break maybe :-)
Jan Algermissen
Thanks for the reply Darrel. You wrote a very good tutorial how to define a REST-service interface. :) (Altough this is not what the question topic was.)
Tuomas Hietanen
Short answer: Use query string parameters when you want to access sets of resources via different axes. All the tools should support those.
Darrel Miller
+3  A: 

Tuomas,

what you are looking for are URI matrix parameters: http://www.w3.org/DesignIssues/MatrixURIs.html http://stackoverflow.com/questions/401981/when-to-use-query-parameters-versus-matrix-parameters.

Jan

Jan Algermissen
Hmm, read too quickly. Darrel's answer is more to the point. But mine is probably useful, too.
Jan Algermissen
Thanks for the reply. Actually this is more what I asked. Those example urls were there just to demonstrate that you have too much work just to declare the shape of the interface. When actually the shape won't bring you the functionality, nor enough freedom.
Tuomas Hietanen