On a recent thread[1], Ruben Verborgh asserted that "...in the longterm, we should convince developers to just provide machine-readable representations of the resources they offer through their websites".
I've been on the other side of that debate for a few years, but Ruben's arguments on his blog [2] are compelling enough to get me to reconsider my position.
I rest my stance on two ideas.
- Websites change at different rates than APIs.
- Websites change for different reasons than APIs.
Coupling the two is problematic.
For certain kinds of sites, like the info sites mentioned in the blog post, this approach may make sense. I don't think there is "One True Way".
However, lets take a simple blog site as an example. For a post, you have the post, but you also have navigation to next articles, comments, tag clouds, archive links, roll call, ads, etc, etc. Which of these things do you get for the json representation? What heuristic do you follow to decide?
I'm perfectly happy is there is asymmetry between representations. It's just not clear how to make expectations predictable to a programmer.
Say you have /posts/123 which reveals /posts/123.json and /posts/123.html as "alternate representations".
Is it "ok" if GET /posts/123 Accept: text/html returns something different from GET /posts/123.html?
I think I can live with any answer here.
The "reasons for change" argument carries more weight.
If a business person says "I want to change the blog so that all posts infinite scroll on the home page" and my response is "but that will break our API clients", that conversation isn't going to go well.[3] Humans are resilient to change and various stakeholders like to "play" with the website in ways that may not be conducive to a backwards compatible api.
Following onto that, the pace of change leads to decisions that might be acceptable for a human centered experience, but disastrous for machine clients. There's probably little to no thought given to "compatibility for a client built a year ago" when someone wants to change a website.
I consider myself persuadable on this topic.
Thoughts?
Alternate opinions from the two presented?
[3] Ignore whether or not this is a bad idea. The reasons for or against doing a website design change shouldn't ride on api client compatibility.