IDigBio API v1 Examples: Difference between revisions

clarify and reorg →‎Viewing JSON Output
(add link to jsonview →‎JSONView Browser Extension)
(clarify and reorg →‎Viewing JSON Output)
Line 8: Line 8:


Javascript Object Notation ([http://en.wikipedia.org/wiki/JSON JSON]), is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. JSON has become a common format for interchanging data via APIs and especially modern Web Services. Effective use of the iDigBio API will require some understanding of JSON.
Javascript Object Notation ([http://en.wikipedia.org/wiki/JSON JSON]), is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. JSON has become a common format for interchanging data via APIs and especially modern Web Services. Effective use of the iDigBio API will require some understanding of JSON.
==== JSONView Browser Extension ====
For best viewing of JSON results in a browser, one may wish to use the [http://jsonview.com/ JSONView Extension] which is available for Firefox and Chrome.
[[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]]


Most of the examples provided here will be shown using the <code>curl</code> command-line tool.  Here are some of the more commonly used curl options (for descriptions and additional usage information, see the curl man page):
Most of the examples provided here will be shown using the <code>curl</code> command-line tool.  Here are some of the more commonly used curl options (for descriptions and additional usage information, see the curl man page):
Line 30: Line 22:
</pre>
</pre>


A short JSON document is returned by the API when calling the GET method (curl's default) against the base URL:
A short JSON document is returned by the API when calling the HTTP "GET" method (curl's default) against the base URL:


<pre>
<pre>
$ curl -s -i http://api.idigbio.org/
$ curl http://api.idigbio.org/
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 108
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, Api-Version, Response-Time
Access-Control-Allow-Methods: GET
Access-Control-Expose-Headers: Api-Version, Request-Id, Response-Time
Connection: Keep-Alive
Content-MD5: airVCXBxEpZm/Wl/DU6tXw==
Date: Fri, 09 May 2014 19:34:26 GMT
Server: restify
Request-Id: ee775220-d7b0-11e3-8828-37453f55c1c8
Response-Time: 2


{"v1":"http://api.idigbio.org/v1/","v0":"http://api.idigbio.org/v0/","check":"http://api.idigbio.org/check"}
{"v1":"http://api.idigbio.org/v1/","v0":"http://api.idigbio.org/v0/","check":"http://api.idigbio.org/check"}
</pre>
</pre>


It may be useful to inspect the API's JSON document outputs using a "pretty printing" feature of some kind. This will make it more readable by humans and also allow it to be more easily filtered using tools such as <code>grep</code>. Two common tools for this available on Unix/Linux are python's json.tool module or the json_pp command-line Perl script (JSON::PP). In typical Unix fashion, these tools can receive input from a pipe and be used to chain multiple commands together.


It may be useful to format the output of the JSON document using a "pretty printing" feature of some kind. This will make it more readable by humans and also allow it to be more easily filtered using tools such as <code>grep</code>. Two common tools for this available on Unix/Linux are python's json.tool or the json_pp command-line Perl script (JSON::PP). These tools can receive input from a pipe in the normal Unix fashion to chain multiple commands together.
There are also ways of viewing JSON inside of a web browser.
 
==== JSONView Browser Extension ====
 
For best viewing of JSON results in a browser, one may wish to use the [http://jsonview.com/ JSONView Extension] which is available for Firefox and Chrome.
 
Here is a screenshot of the output using the JSONView extension after requesting the same API base URL:
 
[[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]]


==== json.tool ====
==== json.tool ====
1,554

edits