Resources and Representations Redux

In response to my post about why it’s so hard for developers to understand REST, Alex Bunardzic talks about the importance of distinguishing resources and representations. I didn’t touch on the subject in my post, but Alex is right on the money that it’s a key distinction in REST that you must understand.

Dreaming of Chairs

If you read through the rest-discuss archives you’ll likely come to the same conclusion as Alex – many developers don’t understand the difference between resources and representations.

But what’s weird is the resource/representation distinction is a fundamental part of our spoken language and our understanding of the world. So we all understand the difference.

Think of a noun, let’s say a chair. We all have an idealized version of a chair in our minds – its something you sit on that usually has four legs, but not always. This idealized version of a chair is something that exists only in our minds. In REST terminology, its a resource.

Now if you look around you’ll see there’s an almost infinite number of ways that the idea of a chair can be translated into a real, actual chairs. Here are just a few examples:

Side Chair
Crater Chair
Chair Small

Each of these real chairs is a representation of the chair resource.

We all understand the difference between the idea of a chair and real chairs, and thus between resources and representations. Therefore the only reason I can see why developers don’t see the distinction in REST is simply because they are stuck in the wrong frame of reference like I discussed yesterday.

Dreaming of Web Sites

Now let’s apply this distinction to the web. The W3C’s Architecture of the World Wide Web document has a great illustration showing the differences between identifiers, resources and representations.

WebArch

The resource is a weather report for Oaxaca, Mexico. The resource only exists as a concept, you can’t touch it, you can’t feel it, its only in the mind of whoever created the Oaxaca weather report website. The website returns a representation of the weather report as an XHTML document, but it could also return an Atom feed, an image, etc.

Forecast

Is This Important?

Is this really important – are resources really key to understanding REST? Let me quote an exchange on rest-discuss between Walden Mathews and Roy Fielding.

In modeling REST formally, you can remove “resource” from
the picture without harming the purely technical aspects of the
system. What you then end up with is a many-to-many relation
from URI to representations. Perhaps that’s all the Web *really*
is, but it’s hard to find any guidance in the building of useful
systems in that. Put another way, it’s hard to decide what value
such a system might be providing.

Walden Mathews

In response:

And that is the key, really, since the main reason we know that a conceptual resource must exist is because of the number of ways that a link can fail. It is only when people complain bitterly about the lack of an expected sameness that you realize the goal of the link has nothing to do with the listener at the end of the HTTP address, but rather the expectation that it identifies (indirectly, as there is no such thing as direct HTTP identification) something other than the address.

People don’t create links to server software; they create links to information.

Roy Fielding

Let me repeat. People don’t create links to server software; they create links to information. Service Oriented Architectures are about creating links to software. Resource Oriented Architectures are about creating links to information. Change your frame of reference.

  1. Andrew Larcombe
    August 14, 2007

    Plato had this nailed over 2000 years ago. 🙂

    Reply
  2. guillaume
    August 20, 2007

    I don’t agree with the chairs example. In my opinion, your have three ressources, which are different types of chairs. Then you may have different representations of theses ressources : pictures, as shown, text describing them, sound maybe.
    So if you ask for /mysite/chairs you’ll have a list of ressources displayed, and not choices between representations. Else, how could you choose a book from another ? Are “Da vinci code” and Plato’s Republic only representations of the book concept ?

    Reply
  3. Charlie Savage –
    August 21, 2007

    Hi guillaume,

    It depends on what you are trying to accomplish. If its important for your application to distinguish between different types of chairs, then you’d definitely want to make each type of chair (modern, antique, lounge, etc) its own resource. And the same of course goes for books, where the “Da Vinci Code” is its own resource.

    Reply

Leave a Reply

Your email address will not be published.

Top