The REST Client Firefox Add-On
The REST Client Add-On for Firefox is very useful for testing syntax. Download it here: https://addons.mozilla.org/en-US/firefox/addon/restclient/
Using the RESTClient plugin to GET and item
Note: Parameters for other REST clients should be similar to these instructions, but may break the URL down into HOST and GET parts.
In HTTPClient it is very simple to query an item for JSON or XML. Set the "Method" to GET, pointed at the URL of the item we want to query. Change the "Request Header" (or "Add Request Header) so that the "Name" = "Content-Type" and it's "Value" = "application/json" for JSON, "application/xml" for XML, or "application/text" for the normal text that you would see in a web browser.
That's it! Push "Send" and you will be able to see your results in raw and copyable form in the "Response Body" tab or formatted in a "Formatted JSON", "Formatted XML", or "Formatted HTML" tab.
You will also be returned with the "Response Header" in it's own tab with useful information like the Status Code.
Creating a basic New Item from RESTClient
To create a new item using the RESTClient for Firefox we first set the "Method" to "POST" and the URL to point at "www.sciencebase.gov/catalog/item/". The "Content-Type" value must now be set to "application/json" since we are sending it JSON. We put our JSON request into the "Request Body", here we will use the minimum requirements to create a new item, setting just the parentId and the title:
Note: If you haven't used JSON before it is basically just a map with String keys and values that can be Strings or collections of Strings. See http://www.json.org/ for more info.
Note: You must be logged in for this to be successful! You will get a Status Code of 200 even if you are not logged in, but the item WILL NOT be created and it will return Formatted HTML (in the form of a login page) instead of the Formatted JSON of your new item. The reason we use this plugin is because you can sign into usgs in a different tab and then use RESTClient because it will use the saved cookies you created.
Creating a more advanced New Item with RESTClient (using more fields) Example
Adding more fields to an item can be as simple as adding key/value string pairs, but the best way to figure out the formatting is to do a GET on an item that has the fields you are looking for (sometimes you may have to create a new item with these fields and do a get on it).
Nested Strings can be sent like this:
Nested Arrays of Strings can be sent like this:
Nested Arrays of key/value pairs can be sent like this: