views:

68

answers:

3

I just began looking at REST and was wondering what the basic difference between the two representations was. The first one looks pretty nice to me and the second one has to pass some attribute values but the underlying logic seems to be boiling to almost the same thing (I could be mistaken though)

http://url/category/category_id/item_id

AND

http://url/category?category_id={12}&item_id={12334}
+1  A: 

It should be possible for agents to reason about the resource structure:

  • based on the URL, and
  • based on links returned by requests for resources.

The problem with the second representation is that it can be considered as a set unordered keys and values, with no real structure/heirarchy.

David Toso
So you mean to say that the first one can be preferred over the second one? I mean, I really like the first one - it brings order into things but I wasn't really sure if there was any advantage of using the second one instead. And by the way, thank you for the bringing forth the logic of unordered keys.
Legend
Legend
@David: whilst your second assertion is correct, your first is not. Reasoning in a purely RESTful client should be done based on content type and relationships, both of which should be communicated using links returned in resource representations.
jkp
+1  A: 

If you click the button from your tag restful-url you get a good link from this site explaining the difference between those two styles:

http://stackoverflow.com/questions/1622085/how-to-obtain-rest-resource-with-different-finder-methods

Mark Byers
+1  A: 

I think you are labouring under some fundamental misconceptions about what REST is about.

The URL used to access a resource really is a detail and actually should not matter to the client. URL's should really be "discovered" by clients anyway if they follow the HATEAOS principe that is one of the tenets of REST.

Essentially you are right though: either URL could represent the resource you are exposing in the end, but as I say, this really is a detail and it comes down to preference in many cases at what URL you expose something. The point of HATEOAS is to allow you to change the URL's that are used to access resources at-will without affecting clients that work against your existing services.

The following URL's might help you understand some of the properties that make services truly RESTful:

[disclaimer: just because HATEAOS is a principle of REST does not make it easy to do. You will find most of the services on the web do not follow this principle strictly at all, as evidenced by their documentation which is full of URL templates; not the way services should be documented in the ideal world. I'm struggling myself to find good examples of truly RESTful services and clients...]

jkp
Thank You. That sheds a lot of light on the concept...
Legend
@jkp - One of my criticisms of REST is how rigid it is regarding HATEAOS, especially related to published public web services. I understand it's benefits but it ignores the benefits of the improved adoption one gets with a URL that can be composed and entered into the browser. That doesn't mean HATEAOS isn't ideal in a vacuum just that purists RESTful/HATEAOS dismiss the value of adoption rates and the simplicity that enables it.In my perfect world 80% of RESTful systems would be hypertext driven and the other 20% would not.
MikeSchinkel