1,554
edits
(re-organize) |
|||
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. Here are some of the more commonly used curl options (for descriptions and additional usage information, see the curl man page): | |||
< | |||
</ | |||
<pre> | <pre> | ||
Line 28: | Line 15: | ||
-i, --include | -i, --include | ||
-v, --verbose | -v, --verbose | ||
-X, --request <command> | |||
-d, --data <data> | -d, --data <data> | ||
... | ... | ||
</pre> | </pre> | ||
Two common tools 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. | A short JSON document is returned by the API when calling the GET method (curl's default) against the base URL: | ||
<pre> | |||
$ curl -s -i 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"} | |||
</pre> | |||
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. | |||
'''json.tool Example''' | '''json.tool Example''' | ||
Line 54: | Line 63: | ||
} | } | ||
</pre> | </pre> | ||
For best viewing of JSON results in a browser, one may wish to use the JSONView Extension for Chrome and Firefox. | |||
'''JSONView Browser Extension Example''' | |||
[[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]] | |||
=== Three ways to fetch a specific record based on iDigBio GUID === | === Three ways to fetch a specific record based on iDigBio GUID === |
edits