REST API using GET
Most developers like to dive right in and see something working. With that in mind, here is a simple example that returns the total population of the city of Burliongton, Vermont based on the 2017 US Census (ACS).
This example will use the following parameters:
Parameter | Value | URL Parameter |
Authentication token | demo | auth=demo |
Datapoints | ACS - Total Population - Value | data=dem.acs.pop.total.val |
Geographies | Vermont | geo=city:burlington-vt |
If you enter the following into your browser …
https://api.statebook.com/api/v1/getdata?auth=demo&data=dem.acs.pop.total.val&geo=city:burlington-vt
… you will see output that looks like this:
{
"resultset": {
"geography": "city:burlington-vt",
"data": [
{
"datapoint": "dem.acs.pop.total.val",
"period": "2019",
"source": "acs5",
"value": 42545
}
]
},
"status": {
"id": "57f5024e-b8ac-4edb-8a8f-3b1b11760c01",
"timestamp": "2021-06-09T17:29:25.220001Z",
"version": "1.0.0",
"license": "The data returned from this StateBook Data API call is restricted
and may only be used in accordance with the terms of a current and
valid StateBook Data API license. Any other use is strictly prohibited."
}
}
REST API using POST and JavaScript
This same example can be done in JavaScript using the Statebook.getData function. This function has one parameter with four values. The authentication token identifies the user. The callback and fail functions are your JavaScript functions to process the returned data or any error conditions. The request is a JSON buffer containing the datapoints and criteria for this call.
var request = { "data": { "datapoints": [ "dem.acs.pop.total.val" ] }, "criteria": { "geography": "city:burlington-vt" } }; Statebook.getData({ authentication: 'demo', callback: function (response) {}, fail: function (response) {}, request: request });
The response buffer is the same as shown in the REST API example and will be processed by the callback function.
Comments
0 comments
Article is closed for comments.