by icebraining · 15y ago · 0 comments
The good
GitHub uses custom MIME types for all of their responses. They're using the vendor extensions that I talked about in my post, too. For example:
application/vnd.github-issue.text+json
Super cool.
Hmm, I wouldn't call that "good." It's definitively better than sending 'application/json' or 'application/xml', which tell us nothing about the structure of the data, and it's probably inevitable in their context, but "good" would be to use an actual standard mimetype instead.The problem with using mimetypes tied to the service is that it undermines the concept of Uniform Interface, by forcing developers to write clients specifically for that service. Imagine if instead of standardizing on (X)HTML, CSS, JS and a couple of image formats, each website used their own format.
That only works if there is a standard mimetype correctly mapping to the needs of the platform. If you're writing a calendaring application you have one, but that's about it.
> The problem with using mimetypes tied to the service is that it undermines the concept of Uniform Interface, by forcing developers to write clients specifically for that service.
Uh... developers have to write clients specifically for that service unless there is a standard content type which the service can provide. Which happens almost never.
> Imagine if instead of standardizing on (X)HTML, CSS, JS and a couple of image formats, each website used their own format.
Does not follow. APIs and websites have a big difference: one is browsed by a human being, the other one is not.
Standards don't fall from the sky, someone has to write and publish them. An "Issue" format is pretty much usable by any bug tracking software out there - Bugzilla, Redmine, etc. Github could perfectly have talked to them and define some common ground.
Is it their obligation? Of course not. But that would've been a "good" solution. This is just OK.
>Uh... developers have to write clients specifically for that service unless there is a standard content type which the service can provide. Which happens almost never.
See above. Usually it doesn't happen because providers don't make the effort.
But in terms of a REST API, the proper solution would be to use a standard format.
0 domain specific media types (application/json)
1 domain specific media type (application/vnd.github+json)
many domain specific media types (application/vnd.github-issue.text+json, ...)
GitHub's v3 API uses the latter.It seems that that the encoding of the response (html/xml/json/etc) is being conflated with a content specification for the response. XML already allows you declare a schema for validation purposes. There have been a few attempts to standardize this on the JSON side, but that will never be a first-class citizen in JSON (nor do I think they should be).
It appears to me, if you really care about the content of your resource, then you should use the schema facilities provided by your encoding, rather than imposing it universally on the architecture side, as the article implies.
Historically, mimetypes (afaik) have never made any assumptions about the content of a resource, other than it adheres structurally to whatever the mimetype declares. Should be kept that way.
The meaning of the document you're returning.
> XML already allows you declare a schema for validation purposes.
But XML does not let you tag documents with arbitrary schemas. As far as I know, there is no way to include a RelaxNG or Schematron schema reference in an XML document in a standardized manner. Using specialized vendor mime types lets you provide this information: the mime type maps onto (among other things) the schema for the meta-type.
> It appears to me, if you really care about the content of your resource, then you should use the schema facilities provided by your encoding
There is nothing saying they can't go hand in hand. Indeed, it's quite the opposite: the vendor mime type you get maps directly to a corresponding schema for validation (the client generally should not validate what it gets, really, though it can).
> Historically, mimetypes (afaik) have never made any assumptions about the content of a resource, other than it adheres structurally to whatever the mimetype declares.
That's very much incorrect. See: application/xhtml+xml, application/svg+xml, model/x3d+vrml, application/soap+xml. And on the vendor-specific side of things, application/vnd.google-earth.kml+xml.
There are plenty of IANA approved mimetypes which define a schema - in fact, HTML itself provides plenty of semantic information about the data.
I'm undecided now though.
It's a slippery slope with custom representations. With generic XML or JSON, you still need a priori knowledge of the content to parse the reprentation manually. Then the benefit of a nonstandard mimetype is simply to be absolutely explicit about your content. Whether that should be canonical, I'm not sure.
In this case, I think the best solution would be to develop a standard "issue format" that would be used by all bug trackers, instead of each having its own. In another example, the "Users" part of the API could very well reuse one of the existing formats.
This also circles back to a (controversial) opinion I have, which is that JSON isn't the best solution for most of these services. With all of its flaws, XML has features like namespaces which enable a better reuse of standard formats - in the "Issues" example, where there is a "user" key, an XML document could integrate a foaf:Person element which is standardized.
And that's what github does: the `+json` postfix indicates that they're returning a JSON dialect, the `vnd.github-issue.text` explains what that dialect precisely is.