1,554
edits
Line 7: | Line 7: | ||
=== Viewing JSON Output === | === Viewing JSON Output === | ||
Most of the examples provided here will be shown using the <code>curl</code> command-line tool. The dollar sign <code>$</code> is an indication of a command prompt where something is typed into a shell or terminal. To run the commands, the <code>$</code> should be omitted. | |||
Here are some of the more commonly used curl options in our examples (for descriptions and additional usage information, see the curl man page): | |||
<pre> | <pre> | ||
Line 15: | Line 15: | ||
... | ... | ||
-s, --silent | -s, --silent | ||
-v, --verbose | -v, --verbose | ||
-d, --data <data> | -d, --data <data> | ||
... | ... | ||
</pre> | </pre> | ||
Many of the examples will also include "pipes" to chain multiple commands together. The [http://en.wikipedia.org/wiki/Pipeline_(Unix) Wikipedia article on Unix software pipelines] may be a useful reference. | |||
==== Javascript Object Notation (JSON) Quick Intro ==== | |||
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. | |||
A simple JSON document with two fields and two data values would look something like this: | |||
<pre> | <pre> | ||
{ | |||
"field1" : "value_a", | |||
"field2" : "value_b" | |||
} | |||
</pre> | |||
If we were storing data about John Smith, age 50, we might represent it as the following JSON document: | |||
<pre> | |||
{ | |||
"lastName" : "Smith", | |||
"firstName" : "John", | |||
"age" : "50" | |||
} | |||
</pre> | |||
A short JSON document is returned by the iDigBio API when calling the HTTP "GET" method (curl's default) against the base URL (http://api.idigbio.org): | |||
{"v1":"http://api.idigbio.org/v1/"," | <pre> | ||
{ | |||
"v1" : "http://api.idigbio.org/v1/", | |||
"check" : "http://api.idigbio.org/check", | |||
"v0" : "http://api.idigbio.org/v0/" | |||
} | |||
</pre> | </pre> | ||
Line 38: | Line 64: | ||
==== JSONView Web Browser Extension ==== | ==== JSONView Web Browser Extension ==== | ||
For | For 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 | Here is a screenshot of the output using the JSONView extension after requesting the API base URL: | ||
[[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]] | [[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]] | ||
Line 73: | Line 99: | ||
If a Python installation is misssing the json standard library, the separate simplejson package may solve the problem. | If a Python installation is misssing the json standard library, the separate simplejson package may solve the problem. | ||
The simplejson.tool module can be invoked in the same way as json.tool: | The simplejson.tool module can be invoked in the same way as json.tool: |
edits