Database Reference
In-Depth Information
and it has a simple and open standard. Dynamic programming languages
such as Python can automatically turn JSON values into typed objects that
make parsing trivial. For example, in Python, the following code snippet
turns a JSON string into a dict object letting you access the fields as keys:
>>> import json
>>> json_str = '{"a": 3, "b": "foo"}'
>>> json_dict = json.loads(json_str)
>>> print json_dict['a']
3
The choice of encoding is another advantage REST has over SOAP—SOAP
generally uses XML, which is much more difficult to parse. The code in
almost any programming language would be much more complex to parse
than the same values encoded in XML.
REST Resources
As previously mentioned, REST collections are collections of resources. But
what is a resource? A resource is any object that you want to perform
operations on. In BigQuery, the resources are the same as the principal
abstractions discussed in Chapter 4: project, dataset, table, table data, and
job.
All Google API resources have a number of common fields. Because these
fields are considered boilerplate, many of the examples in this chapter omit
them to just highlight the more interesting aspects of the API. Here is a
curl request that gets the dataset object for the scratch dataset we created
earlier, showing only the common fields discussed in this section (we also
set up a couple of handy environment variables in order to save some
typing):
$ BASE_URL= https://www.googleapis.com/bigquery/v2
$ PROJECTS_URL=${BASE_URL}/projects
$ PROJECT_URL=${PROJECTS_URL}/${PROJECT_ID}
$ DATASETS_URL=${PROJECT_URL}/datasets
$ DATASET_URL=${DATASETS_URL}/scratch
$ curl -H "$(python auth.py)" \
"${DATASET_URL}"
{
Search WWH ::




Custom Search