tags:

views:

100

answers:

3

What is the benefit of Connectedness as defined by Resource Oriented Architecture (ROA)? The way I understand it, the crux of Connectedness is the ability to crawl the entire application state using only the root URIs.

But how useful is that really?

For example, imagine that HTTP GET http://example.com/users/joe returns a link to http://examples.com/uses/joe/bookmarks.

Unless you're writing a dumb web crawler (and even then I wonder), you still need to teach the client what each link means at compile-time. That is, the client needs to know that the "bookmarks URI" returns a URI to Bookmark resources, and then pass control over to special Bookmark-handling algorithms. You can't just pass links blindly to some general client method. Since you need this logic anyway:

  1. What's the difference between the client figuring out the URI at runtime versus providing it at compile-time (making http://example.com/users/bookmarks a root URI)?

  2. Why is linking using http://example.com/users/joe/bookmarks/2 preferred to id="2"?

The only benefit I can think of is the ability to change the path of non-root URIs over time, but this breaks cached links so it's not really desirable anyway. What am I missing?

A: 

Its easier to extend, and you could write small apps and scripts to work along with the core application fairly easily.

Added: Well the whole point starts with the idea that you don't specify at compile-time how to convert URIs to uids in a hardcoded fashion, instead you might use dictionaries or parsing to do that, giving you a much more flexible system.

Then later on say someone else decides to change the URI syntax, that person could write a small script that translates URIs without ever touching your core Application. Another benefit is if your URIs are logical other users, even within a corporate scenario, can easily write Mash-ups to make use of your system, without touching your original App or even recompiling it.

Of course the counter side to the whole argument is that it'll take you longer to implement a URI based system over a simple UID system. But if your App will be used by others in a regular fashion, that initial time investment will greatly payback (it could be said to have a good extensibility based ROI).

Added: And another point which is a mater of tastes to some degree is the URI itself will be a better Name, because it conveys a logical and defined meaning

Robert Gould
I'm not sure I understand what you mean. Care to elaborate?
Gili
What prevents you from using "logical names" as your custom IDs and mapping them to the real database IDs underneath the hood? For example, id="2" would be id="john" instead. I understand the benefit of logical IDs but this doesn't seem to answer my question.
Gili
Unfortunately, I think I HAVE answered the "why", problem is the "why" isn't what you want to do. So you don't want to use URIs, which is perfectly fine. The arguments are no more valid than object oriented versus procedural programming. Its a just a mind-set and programming philosophy, nothing more
Robert Gould
I am honestly trying to understand why URIs are beneficial. I get the feeling they are and I'm trying to embrace ROA as much as possible, but I believe it is vital to understanding *why* its best practices are beneficial instead of applying them blindly.
Gili
You made a great argument for why resource URIs should use logical IDs (instead of database IDs). But *exposing* a resource URI using logical IDs is not the same thing as *referencing* such a URI from another resource representation. I understand why the former is beneficial, but why is the latter?
Gili
It's about to principles, having a unified model for exposing and referencing is "better" than two separate models (in most cases). Also anyone (human) can look at a resource and understand it. In the end it's about placing Human needs over Machine needs. because any other purpose can be emulated.
Robert Gould
+1  A: 

You are right that changing Uris is not desirable but it does happen and using complete Uris instead of constructing them makes change easier to deal with.

One other benefit is that your client application can easily retrieve resources from multiple hosts. If you allowed your client to build the URI's the client would need to know on which host certain resources reside. This is not a big deal when all of the resources live on a single host but it becomes more tricky when you are aggregating data from multiple hosts.

My last thought is that maybe you are oversimplifying the notion of connectedness by looking at it as a static network of links. Sure the client needs to know about the possible existence of certain links within a resource but it does not necessarily need to know exactly what are the consequences of following that link.

Let me try an give an example: A user is placing an order for some items and they are ready to submit their cart. The submit link may actually go to two different places depending on whether the order will be delivered locally or internationally. Maybe orders over a certain value need to go through an extra step. The client just knows that it has to follow the submit link, but it does not have compiled in knowledge of where to go next. Sure you could build a common "next step" type of resource so the client could have this knowledge explicitly but by having the server deliver the link dynamically you introduce a lot less client-server coupling.

I think of the links in resources as placeholders for what the user could choose to do. Who will do the work and how it will be done is determined by what uri the server attaches to that link.

Darrel Miller
A: 

I'll add my own answer:

  1. It is far easier to follow server-provided URIs than construct them yourself. This is especially true as resource relationships become too complex to be expressed in simple rules. It's easier to code the logic once in the server than re-implement it in numerous clients.
  2. The relationship between resources may change even if individual resource URIs remain unchanged. For example, imagine Google Maps indexes their map tiles from 0 to 100, counting from the top-left to the bottom-right of the screen. If Google Maps were to change the scale of their tiles, clients that calculate relative tile indexes would break.
  3. Custom IDs identify a resource. URIs go a step further by identifying how to retrieve the resource representation. This simplifies the logic of read-only clients such as web-crawlers or clients that download opaque resources such as video or audio files.
Gili