A place to cache linked articles (think custom and personal wayback machine)
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 лет назад
12345
  1. title: Hypermedia, past, present and future
  2. url: http://www.bizcoder.com/hypermedia-past-present-and-future
  3. hash_url: 54a331f9e18d360395f266e100076cb1
  4. <p>Hypermedia is not a new concept, it has been around in various forms since the 1960s.  However, in the past seven years there has been a significant resurgence of interest in the concept.  This blog post contains my reflections on the past few years, where we currently are and where we might be headed in the use of hypermedia for building distributed applications.</p><p><img src="http://davy.potdevin.free.fr/Site/pics/gods/janus-big.gif"/></p><h3>The HTML years</h3><p>The majority of developers have only been exposed to hypermedia via HTML.  HTML is an "in-your-face" example of the success of hypermedia, and yet in most Web API related discussions it is often dismissed with "well that's different".  A distinction is made by many between human-2-machine interactions and machine-2-machine interactions.  This distinction is used to explain why API interactions are different.  To be honest, I've yet to see my parents open a web browser and construct a HTTP request by hand.  The Web Browser is itself is a client application, running code that makes HTTP requests.  It is not completely autonomous, but no human invokes calls to load a stylesheet, javascript snippet, or embedded image.  </p><p>On the other hand, the web crawlers used by search engines are autonomous and they also consume HTML hypermedia.</p><p>There were numerous efforts over the years to present HTML, or more specifically XHTML as a viable media type for Web APIs.  <a href="https://www.google.ca/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0CB0QtwIwAA&amp;url=http%3A%2F%2Fvimeo.com%2F20781278&amp;ei=1jnBVLD6NYWjNpiZgvAE&amp;usg=AFQjCNHiOTW6bTCI6esUYrLR_giukF-ARA&amp;bvm=bv.83829542,d.eXY">Jon Moore</a> from Comcast made the biggest splash, but Microsoft made efforts in this area and I participated in workshops a RESTfest where we used XHTML as the response media type.</p><p>Despite this, the use of HTML in Web APIs has never really gained significant traction.</p><h3>RDF's lofty goals</h3><p><a href="http://www.w3.org/RDF/">RDF</a> has been around for almost as long as HTML, but it has never really made significant progress outside of academia.  I've talked to a significant number of very smart people who believe RDF is the answer.  However, I suspect it is the Xanadu, or the betamax of media types.</p><p>The challenge with RDF is that can be quite difficult to grok.  First of all there are a variety of different serialization formats: turtle, n3, <a href="http://www.w3.org/TR/xhtml-rdfa-primer/">RDFa</a> and now <a href="http://json-ld.org/">JSON-LD</a>.  This can make learning RDF tricky because really need to learn the conceptual model and then learn the mapping used for serialization.</p><p>The model of RDF is based around triples, i.e. Subject, predicate and object, where these elements are often identified using URIs.  This can produce quite cumbersome looking documents.</p><p>My experience has been that most developers don't have the patience for the sophistication of RDF and quickly want to hide the complexity with tooling.  Tooling can hurt or help, it just depends on who is writing the tooling and what there goals are.</p><p>It is possible that I could be proved wrong by JSON-LD.  A number of organizations are starting to adopt JSON-LD.  Only time will tell if it will stick.</p><h3>Feeds</h3><p><img align="right" alt="File:Feed-icon.svg" src="http://upload.wikimedia.org/wikipedia/en/thumb/4/43/Feed-icon.svg/128px-Feed-icon.svg.png"/>The RSS format was originally based on an early working draft of RDF.  In 2005 the Atom Syndication Format was released as replacement for RSS.  Both these formats had the specific goal of allowing content creators and distributors to advertise regularly produced along with metadata about the content.</p><p>These formats spawned the creation of a wide range of new client applications that could consume this format.  </p><h3>Feeds As Containers</h3><p>The success of the Atom format spurred API providers to consider using Atom as a container of data other than blog posts and new items.  Big players like Google and Microsoft created <a href="https://developers.google.com/gdata/">GData</a> and <a href="http://www.odata.org/">OData</a> that were similar ideas where Atom was used as an envelope for API data.</p><p>In order for feed readers to be useful, they needed to understand the contents of the Atom Entry element.  Most often this content was HTML and could be rendered with a HTML rendering library.  However, when Atom feeds were used in APIs for carrying non-HTML data there was no standardized way for clients to understand the contents of the Atom Entry.  The custom data content was identified using XML namespaces that a client was expected to recognize.  Unfortunately, XML namespaces introduce URIs and prefixes and the ability to mix multiple namespaces in a single document.  This starts to bring back the complexity of RDF.</p><p>GData didn't really last very long and OData has some successes and some failures and is currently on version 4.</p><p>Overall OData was more ambitious than Gdata in that it defined a standardized querying mechanism and built on top of Microsoft's CSDL which is a metadata language used by the ORM, Entity Framework.  This allowed lots of tooling to be built around OData.</p><p>Another more recent effort in this area is <a href="http://activitystrea.ms/">Activity Streams</a>.  Initially, I understood this to be a generalized way of advertising lists of events that occur, it seems to have evolved into not only an activity stream container, but a mechanism for describing activities using vocabularies.</p><h3>Linking and Embedding</h3><p>Late 2010 saw the beginning of flurry of activity in the hypermedia space.  Mike Kelly created <a href="http://stateless.co/hal_specification.html">HAL</a> which defined a JSON based format that supported linking to other resources and embedding portions of other resources into representations.</p><p>In 2011 <a href="http://amundsen.com/media-types/collection/">Collection+Json</a> was created by Mike Amundsen that provides a way of representing a list of things as well as methods to search the list and add to the list.</p><p><a href="https://github.com/kevinswiber/siren">Siren</a>, <a href="https://github.com/JornWildt/Mason">Mason</a>, <a href="http://rawgit.com/uber-hypermedia/specification/master/uber-hypermedia.html">Uber</a> and <a href="http://jsonapi.org/">JsonApi</a> all followed in the following years, all attempting to address perceived shortcomings of HAL and C+J.</p><h3>The Great Form Debate</h3><p>One of the features that has been continually debated is the need for forms support in hypermedia types.  HAL did not support forms. Siren, Mason, C+J and Uber do.  HAL relies heavily on link relation types to convey both read and write semantics.  The authors of the other formats feel it is more valuable to have explicit syntax for describing write operations.</p><p><a href="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/DebatingMonks_2.jpg"><img title="DebatingMonks" alt="DebatingMonks" src="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/DebatingMonks_thumb.jpg" border="0"/></a></p><h3>Spoilt For Choice</h3><p>The growing REST community has learned a great deal in the process of developing these specifications.  However, they are left with a whole new problem.  Developers who want to start down the path of using hypermedia in their APIs need to make a choice between a range of formats that are only subtly different in their capabilities.  How are developers supposed to choose?</p><p><a href="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/BeerTaps_2.jpg"><img title="BeerTaps" alt="BeerTaps" src="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/BeerTaps_thumb.jpg" border="0"/></a></p><p>In the past, choosing a media type was never a particularly difficult proposition because they tend to be built for a specific purpose.  HTML was originally designed for describing a textual document,  image/jpeg is ideal for photographs, text/css for stylesheets,  etc. </p><p>However, this most recent set of media types have focused on message format semantics, i.e the ability to link to other content, embed content and describe affordances, all without saying anything about the application domain.  This has the advantage that they can be used within any application domain, for almost any purpose, however, it also makes them have no meaning, no purpose.</p><h3>Meanwhile On Another Planet</h3><p>In contrast to these generic hypermedia types, in the world of telecommunications, a media type called VoiceXML was developed. </p><p> <a href="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/Planet_2.jpg"><img title="Planet" alt="Planet" src="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/Planet_thumb.jpg" border="0"/></a></p><p><a href="http://www.voicexml.org/">VoiceXML</a> was developed to drive audio and voice response applications.  Related to that effort was <a href="http://www.w3.org/TR/ccxml/">CCXML</a> (Call Control eXtensible Markup Language), <a href="https://tools.ietf.org/html/rfc5707">MSML</a> (Media Server Markup Language), <a href="https://tools.ietf.org/html/rfc4722">MSCML</a> (Media Server Control Markup Language) and most recently <a href="http://www.w3.org/TR/2012/WD-scxml-20120216/">SCXML</a> (State Chart XML).</p><p>All of these media types are used as part of a larger system, but each media type is designed to solve a specific problem domain.   </p><h3>The Great Divide</h3><p>Earlier I accused some media types of having no meaning, no purpose.  This is actually a design objective of some media types.  The idea is that media types can limit their complexity by focusing on just structural and protocol semantics of the message and leave application and domain semantics to a separate mechanism.  Formats like RDF use the a concept called ontologies to describe application semantics.  JSON-LD can also use JSON schemas defined at schema.org.  HAL recently added support for a notion called Profiles that existed in early versions of HTML and has been resurrected in recent years.  The idea of Profiles is that you can independently apply a set of domain semantics to a hypermedia message.</p><p>The advantage of using Profiles is that your API only needs to support a small set of media types, possible only one, and application semantics can be layered on top.  This limits the time and risk involved in designing and documenting new media types.  Mike Amundsen has been spearheading an effort to define a description language called ALPS that makes defining profile description documents possible.</p><h3><a href="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/PaintExplosion_2.jpg"><img title="PaintExplosion" alt="PaintExplosion" src="http://www.bizcoder.com/Media/Bizcoder/Windows-Live-Writer/Hypermedia-past-present-and-future_1465D/PaintExplosion_thumb.jpg" border="0"/></a></h3><h3>Media Type Explosion</h3><p>One of the pieces of lore in the hypermedia community is that we must avoid a phenomenon called "media type explosion".  The fear is that if every API provider begins creating media types for all of their application semantics we will massively dilute the re-usability of media types and potentially introduce security vulnerabilities.  Also, the process of registration and expert review is not designed to be efficient for large numbers of media types that may never be suitable for public consumptions.</p><p>Ironically, the fear of media type explosion has discouraged people from creating media types and therefore have simply resorted to tunneling application semantics over generic media types like application/json.  The result being an explosion of implicit JSON structures.  Not exactly the desired effect.</p><h3>API Media Types</h3><p>A popular alternative to reusing existing media types, or creating media types for each application concept, some APIs have decided to create a single media type definition for the entire API.  This approach provides an API with a central place to document message format conventions and structure.  APIs like GitHub, Heroku and Sun's Cloud API take this approach.  This is an interesting compromise.  However, it limits the potential for re-use because the definition of the media type is scoped to the particular API.</p><h3>Horizontal Media Types</h3><p>Ideally, at least in my opinion, media types would be built that solve a specific problem but could be re-used across many APIs.  The end goal would be to be able to build APIs by composing a set of pre-defined APIs and minimize or even eliminate the need for new media types to support the API.</p><p>Getting widespread agreement on application domain types, like customer, invoice, work task, employee, etc, is especially difficult.  This can be seen if you dig into the history of standards like ANSI X12,  Edifact or UBL.  </p><p>However, there are many aspects of applications that are very similar between applications: users, accounts, permissions, roles, errors, lists, reports, long running operations, filters, tables, graphs, dashboards.</p><p>I believe these are the low hanging fruit for building re-usable media types.</p><h3>Link Relation Types Add Context</h3><p>Media types are not the only way to convey semantic information to a client.  Link relations are an extremely valuable way to add semantic context to more generic media types.  Consider a media type that described a street address.  An address is a fairly well defined concept that could be sufficiently defined for use in a wide range of scenarios.</p><p>Creating link relations like "ShipTo", "InvoiceTo", "Home", "Work", "Destination", can provide sufficient additional semantics to  a fairly generic media type to allow a client to make intelligent choices.</p><p>Even link relations have different styles in the way they are defined.  Some are very generic, like "<a href="http://www.w3.org/TR/html5/links.html#link-type-next">next</a>" and "previous".  Others have precisely defined behaviour like "<a href="https://pubsubhubbub.googlecode.com/git/pubsubhubbub-core-0.4.html">hub</a>" and "<a href="https://tools.ietf.org/html/draft-wmills-oauth-lrdd-07">oauth2-token</a>".</p><h3>So, What Should I Use?</h3><p>If only there were an easy answer to that question.  The hard answer is: learn about the options you have, understand the pros and cons to each approach and then consider the context of the application you are trying to build.  At that point you may have enough information to choose the right solution for your problem.  Good luck!  And make sure you tell everyone about your experiences.  We are all learning together.</p>