HTML is data. It's representation of a resource. A pretty good one, I must say. I'd argue that it's easier to write clients when resources are represented in HTML or other hypermedia. In case of HTML, there are many good HTML parsers that let you use xpath and/or CSS selectors. Combined with RDFa or microformats, you can easily build robust clients. HTML even defines <form> and other links for updating resources.
With JSON, in my experience, it's very easy to write brittle clients that will break if server changes representation just a little. There's JXON, but I haven't used it in production.
It's your experience vs the industry consensus. The industry is currently shifting away from HTML services and to JSON.
My belief as to why is that HTML is a markup language specifically meant for display in a web browser and JSON is an object serialization format. Even with pure XML you have issue when you have a block like:
<issues>
<issue>Data</issue>
</issues>
Should issues be represented internally as an object/map or as an array? Will I ever get more than 1 issue tag? In JSON you have maps and arrays that map directly to the native constructs in your language in a 1 to 1 fashion. XML has a many to many relationship. I have at least 3 ways to represent key/value pairs in XML but only 1 in JSON. I have structures in XML where I'm not sure if they are an array or a key value pair map.
The common way to solve this in xml is by using a schema but that is the definition of brittle. Now you have to bump the api version for every little change even if you are just adding a field. In a JSON based service this is not the case.
Then we add in the fact that for correct display in your page you will likely need classes and divs that are not data. Those are clearly display markup and make your data tightly coupled with the display. Your xpath ends up not representing your business data instead ends up representing your display structure.
I hope you heard of semantic markup. And give me one crawler/search engine of JSON resources. I give you few search engines of HTML resources: google.com bing.com duckduckgo.com
Semantic markup isn't really useful for APIs, though. Web pages, sure, but if you're worried about your AJAX API being friendly to screen readers, rather than Javascript/other languages, you have some amusingly misplaced priorities.
-4
u/passwordissame Mar 18 '14
HTML is data. It's representation of a resource. A pretty good one, I must say. I'd argue that it's easier to write clients when resources are represented in HTML or other hypermedia. In case of HTML, there are many good HTML parsers that let you use xpath and/or CSS selectors. Combined with RDFa or microformats, you can easily build robust clients. HTML even defines
<form>and other links for updating resources.With JSON, in my experience, it's very easy to write brittle clients that will break if server changes representation just a little. There's JXON, but I haven't used it in production.