Tuesday, March 29, 2011

Feature of the Week: API outputs JSON instead of XML

In the last post we introduced a new parameter for our REST API. With the last release another new API feature was introduced which allows for a better usage of BibSonomy in browser based applications. The API is now able to output JSON. Instead of XML, all API request can be switched with the URL parameter format to return JSON. The JSON output of the last post's example with alphabetical ordered tags of the user beate can be accessed by the following request (you need your username and API key to access the URL):

http://www.bibsonomy.org/api/tags?user=beate&start=0&end=100&order=alph&format=json

If you would like to force the API to provide the XML version you need to change the parameter format to format=xml.

Another option to switch between the two output formats is the Accept parameter send to the server in the header of the HTML request. The screenshot below shows the typical XML output (top part of the figure) and parts of the request header (bottom). Besides the typical text/html format, the request asks for application/xml as one output option. If this is changed to application/json the API will send the answer in JSON format.


If you would like to try it yourself you can use the Firefox addon Modify Headers.

We hope you will find the new feature useful. Every feedback is very welcome.

Happy Tagging,
Andreas

Popular Posts