InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Is Proliferation Of Custom Media Types RESTFul?

Posted by Dilip Krishnan on Jan 11, 2010

Sections
Architecture & Design,
Enterprise Architecture,
Operations & Infrastructure
Topics
REST ,
SOA ,
Versioning

Subbu Allamaraju, revisits one of the recurring debates in the REST community; the standard media types vs. custom media types and tries to determine the best practices when using them. He starts with the stating dichotomous views on the use of media types.

  • Opinion 1: Web services must use standard media types to be RESTful.
  • Opinion 2: Custom media types are necessary to keep interactions visible, and to serve as contracts.

The first opinion which, if adhered to strictly, per Roy Fieldings thesis, “the use of media types such as application/vnd.example.myway+xml is not RESTful”. Subbu believes that understanding the impact of such media type usage in the real world is more important than following the thesis to the letter. There are however comments that suggest that this interpretation of the thesis might be up for debate as well.

To the contrary, the second opinion, he says, leads to visibility of the messages at the protocol level via the use of custom media types.

[…] For instance, how can anyone know if a representation that uses application/xml media type describes a purchase order, or a photo album? If the web service uses media types likeapplication/vnd.example.po and application/vnd.example.album, then any one can interpret the semantics of the representation without parsing the body of the representation. Per this line of thinking, a media type is an identifier for message semantics, and message recipients use media types to trigger processing code.

“So what is the right thing to do?”  He asks, as he puts forth his idea, in a effort to democratically determine the best practices

  • If the sender is formatting representations using standard extensible formats such as XML or JSON, use standard media types such as application/xml and application/json.
  • Mint new media types when you invent new formats.
  • If you are just looking for a way to communicate application level semantics for XML and JSON messages, use something else (e.g. XML namespaces and conventions).
  • If the goal is versioning, use version identifiers in URIs.

Giving java-like examples, He asserts that though its possible to peek into the messages to see how a request can be processed, it compromises visibility or opacity as the case may be.

Media types such as application/xml and application/json are good enough for XML and JSON message processing in code. […] URI based approaches are guaranteed to work across the stack. Ignoring real-world interoperability for the sake of "architectual purity" or "RESTful contracts" may eventually back fire.

Via the post is the solution presented by Subbu found the right balance between architectural purity and interoperable real-world solutions? Be sure to visit the original post to weigh in your opinion.

  • This article is part of a featured topic series on SOA
Custom media types and coupling by Satadru Roy Posted
Re: Custom media types and coupling by Dilip Krishnan Posted
  1. Back to top

    Custom media types and coupling

    by Satadru Roy

    Code extract from the blog:
    <<

    if("application/vnd.example.po").equals(response.getMediaType())) {
    // process purchase orders
    }
    else if("application/vnd.example.album").equals(response.getMediaType())) {
    // process albums
    }
    >>

    How is this any less coupled than the out-of-fashion RPC:

    processPO(poxml) or processAlbum(albumxml)?

    Not trying to be provocative just looking to be educated.
    <>

  2. Back to top

    Re: Custom media types and coupling

    by Dilip Krishnan


    How is this any less coupled than the out-of-fashion RPC:

    processPO(poxml) or processAlbum(albumxml)?

    Not trying to be provocative just looking to be educated.

    I believe if u look at the larger use case picture the difference will be apparent. Think of an adhoc http client that requests for reprensentation of an album or po. The only coupling the client needs to have is the locations of the representations. Every other coupling can be either a client-just-knows kind or some out-of-band formal metadata exchange.

    Secondly the http method of interaction determines the nature of the operation safe/unsafe/idempotence etc unlike an RPC interaction.

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.