Sunday, March 23, 2008

REST, Hypermedia, and JSON

Enjoying Sam Ruby's latest post titled Connecting, I was reminded that designing a RESTful system means much more than just adhering to a uniform interface (often the first attribute of a ROA that is promoted).

When designing a Resource Oriented Architecture, you mustn't forget about hypermedia and how your resources link to one another, and how those links are expressed through your representations.

Which brings me to JSON. A nifty little format, indeed. And one that, if you are building a modern web service, you should be investigating and implementing. However, if you are indeed building a hypermedia system with JSON, how do you express your links?

I know how to do this in XHTML and RDF, but not sure how to express or render a URI and have it mean "link".

I've love to be able to do something like this:


{
"name": "Cool Beans",
"account": "http://example.org/accounts/23242342"
}


However, any JSON client will have a tough time determining what the meaning of the account value is. Sure, it's a string. But how should it be treated? And how do I express that to my JSON clients? I'm not about to give them a regular expression and say "if it matches, it's a URI, and follow it!"

Thoughts? How to express hypermedia in JSON?
Post a Comment

Disclaimer

I'm probably required to say that the views expressed in this blog are my own, and do not necessarily reflect those of my employer. Also, except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the BSD License.