What is the difference between category/category_id/item_id and category?category_id={}&item_id={} in REST?

StackOverflow https://stackoverflow.com/questions/1777447

Question

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}
Was it helpful?

Solution

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...]

OTHER TIPS

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.

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:

How to obtain REST resource with different finder "methods"?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top