I am developing a REST API for my web application for public use.
I am tempted to provide only JSON as format for the response as it is more lightweight than XML (on large traffic, any byte counts).
I think any programming language and platfo开发者_开发问答rm is able to easily and effectively parse JSON, nowadays.
So, what do you think about providing only JSON and not XML as format for the response?
Thanks,
DanSome quantitative data on XML vs JSON here: http://www.slideshare.net/jmusser/pw-glue-conmay2010 (see slide 11)
From the 2,000 API's they checked, 45% of them supported JSON in 2010 and the numbers we're quite quickly rising. With a total of 132 (of those 2,000) that only accept JSON. No statements we're made about the amount of XML-only API's.
That's pretty much how I work all the time. I found that Google Chrome displays JSON responses out-of-the-box, while XML responses require me to "view source" or cheat using Content-Type: text/plain
. I also find JSON very handy when building command-line mini-tools to interact with web/comet servers, message buses, etc., because there is so much less typing and the typing you have to do is so much easier. For instance try timing yourself as you type this on the command line:
sendmsg foobar/queue1 '<msg><labels><rows><row>a</row><row>b</row><row>c</row><row>d</row><row>e</row></rows></labels></msg>'
vs. this:
sendmsg foobar/queue1 '{"labels":["a", "b", "c", "d", "e"]}'
精彩评论