.. _html_as_media_type: ============================================================ 2012-07-10 **Using HTML as the Media Type for your API** ============================================================ - https://twitter.com/jon_moore - https://blog.jonm.dev/posts/using-html-as-the-media-type-for-your-api/ - :ref:`related_frow` There is an ongoing (and interesting) `discussion `_ on the API-craft mailing list revolving around designing new media types for enabling hypermedia APIs primarily for programmatic consumption. As some folks may know, I like to use HTML as the media type for my hypermedia APIs. `Steven Willmott opined `_ I thought this raised such an interesting implicit question, and I get asked about this enough that I thought it warranted a longer response. There are actually a variety of reasons I prefer using HTML: - rich semantics - hypermedia support - already standardized - tooling support Rich Semantics ================== I’ve heard many folks say that HTML is primarily for presentation and not for conveying information, and hence it isn’t suitable for API use. Hogwash, I say! There are many web experts (like `Kimberly Blessing `_) who would insist that markup is exactly for conveying semantics and that presentation should be a CSS concern. People seem to forget that web sites actually worked before CSS or Javascript was invented! **I rely on this heavily** for my HTML APIs. Hypermedia Support ==================== HTML offers , , and
as obvious examples of hypermedia controls. In fact, the use of to support parameterized navigation (where the client supplies some of the information needed to formulate a request) fairly well sets HTML apart from most existing standard (in the sense of being registered in the IANA standards tree for media types. While currently this construct is not as powerful or expressive as it could be–c.f. only supporting GET and POST for methods–it’s actually enough to get by, and is certainly sufficient for a RESTful system (if you care about qualifying for the label). Furthermore, there are ongoing efforts within the HTML5 standards process to address this. (As an aside, it’s worth noting that