Querying the server¶
To use timetric’s data input/output API, you need to know which series you want to deal with (and thus which URLs to talk to). For example, some things you might want to do:
- You might want a list of all of the series you own
- You might want a list of data tagged in a particular way
- You might want to do an exploratory search of timetric’s data
Relevant URLs¶
There are two URLs involved in querying nugget lists:
/tag/TAGLIST/
/search/
For any queries involving tagging, the collection of series is available under the first URL; for all other queries, the collection is available under the second.
Query axes¶
There are three axes along which you can refine your query:
- Tags
- String search
- Username search
Tag search¶
Series on timetric can be tagged. All data provided by timetric itself is comprehensively tagged; user-generated series will be tagged by their owners. A list of all series with a given tag, britain, can be found at:
/tags/britain/
To search for series tagged with multiple tags, construct a URL with semicolon-separated tags. The list of all series tagged with both britain and economics, can be found at:
/tags/britain;economics/
The order of tags in the URL is not important; you would get the same results from the URL /tags/economics;britain/.
Note
tags may contain any printable Unicode character, including spaces and punctuation. For special characters, quoting is fairly complex. The tag string must be represented as UTF-8-encoded bytes, and then characters outside the set permitted in URLs must be %-encoded according to RFC 3986. When using these tags in a URL, further URL encoding is then necessary; so tags end up needing to be double-URL-encoded.
Thus, the tag public data is actually represented by the string public%20data, and should be written in a URL as:
/tags/public/%2520data/
String search¶
Timetric series have rich metadata; titles, captions, descriptions, etc. Full-text search through these is available, using query parameters in the URL.
From a search endpoint, you would query for “footwear” by appending the following to the URL:
?q=footwear
So, for example, to search over all series, you would look for:
/search/?q=footwear
To do the same search, but only over series tagged with “britain”, you would look for:
/tags/britain/?q=footwear
Note
If your search term needs to include punctuation, special characters, etc., these should be URL encoded. Unlike tags, though, they need only by singly-encoded:
/search/?q=foot%20wear
Username search¶
You can retrieve all series owned by yourself by querying on your username. You can also retrieve lists of other users’ series in the same way (although you will none of their private series will be reported).
To search for all series owned by the user johndoe, append the following to a search endpoint: ?u=johndoe
This can be combined both with tag search and normal search. For example, all of John Doe’s series tagged with cheese may be found at:
/tags/cheese/?u=johndoe
and to query across those series for all series mentioning Gorgonzola:
/tags/cheese/?q=Gorgonzola;u=johndoe
Output formats¶
Search results can be returned in several formats. The default is HTML, but you can also request Atom, as well as two JSON formats (“thick” and “thin”). Selection between the different formats is done by appending results.FORMAT to the path component of the URL.
Thus:
/search/results.atom?u=johndoe
shows details about John Doe’s data, in an Atom format, while:
/tags/cheese/results.thin.json?q=Gorgonzola
shows details about series tagged with cheese, with Gorgonzola in the description, and gives the details in the thin json format.
HTML
HTML results can be viewed in a browser. The structure of the HTML is liable to change, but it will always be usefully viewable in a browser.
Atom
Atom results are given in the Atom/Opensearch format (see http://opensearch.org).
Example output:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"> <title>Timetric Search: </title> <link href="http://timetric.com/search/results.atom?q=footwear;n=20;p=1"/> <updated></updated> <author> <name>Timetric</name> </author> <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> <opensearch:totalResults>371</opensearch:totalResults> <opensearch:startIndex>1</opensearch:startIndex> <opensearch:itemsPerPage>20</opensearch:itemsPerPage> <opensearch:Query role="request" searchTerms="footwear" count="20" startPage="page.number"/> <link rel="alternate" href="http://timetric.com/search/?q=footwear;n=20;p=1" type="text/html"/> <link rel="self" href="http://timetric.com/search/results.atom?q=footwear;n=20;p=1" type="application/atom+xml"/> <link rel="first" href="http://timetric.com/search/results.atom?q=footwear;n=20;p=1" type="application/atom+xml"/> <link rel="next" href="http://timetric.com/search/results.atom?q=footwear;n=20;p=2" type="application/atom+xml"/> <link rel="last" href="http://timetric.com/search/results.atom?q=footwear;n=20;p=19" type="application/atom+xml"/> <link rel="search" href="http://timetric.com/opensearch.xml" type="application/opensearchdescription+xml"/> <!-- results --> </feed>
and each result will look something like:
<entry> <title>03.2.2 Footwear Repair and hire of footwear CP SA : yearly</title> <link href="http://timetric.com/series/_1H7WjD9RKS0-W3qOzOqIw/"/> <id>tag:http://timetric.com,2009-06-23:SearchResults:_1H7WjD9RKS0-W3qOzOqIw</id> <updated>2009-07-06T13:00:17</updated> <content type="text"> Crown copyright. Source: National Statistics website:www.statistics.gov.uk. Crown copyright material is reproduced with the permission of the Controller Office of Public Sector Information (OPSI). (from http://www.statistics.gov.uk/statbase/tsdlistfiles.asp) </content> </entry>
JSON
JSON results are closely modelled after the opensearch format; a dictionary is returned, giving both pagination details (with names identical to those in the opensearch spec) and results. Typical JSON output would look like:
{"totalResults": 371, "startIndex": 1, "itemsPerPage": 20, "links":{ "self": "http://timetric.com/search/results.thin.json?q=footwear&p=1&n=20", "first": "http://timetric.com/search/results.thin.json?q=footwear&p=1&n=20", "previous": null, "next": "http://timetric.com/search/results.thin.json?q=footwear&p=2&n=20", "last":"http://timetric.com/search/results.thin.json?q=footwear&p=19&n=20" }, "results": [ /* list of search results */ ] }
while the series details appear in the results list:
Thin JSON
In thin JSON, the details given for each series consist only of its id and URL:
{ /* pagination */ "results": [ {"name": "adR4JS_USY2ljLZPehLbKQ", "url": "http://timetric.com/series/adR4JS_USY2ljLZPehLbKQ/"}, /* more results */ ] }
Thick JSON
In thick json, the details given for each series include those for thin JSON, and also:
- title
- caption
- description
- units
- origin
- license
Example output:
{ /* pagination */ "results": [ {"name": "adR4JS_USY2ljLZPehLbKQ", "title": "03.2.1 Footwear", "caption": "03.2.1 Footwear Shoes and other footwear IDEF NSA 2003=100 : quarterly", "description": "03.2.1 Footwear Shoes and other footwear IDEF NSA 2003=100 : quarterly", "units": "GBP/100", "origin": "UK Office of National Statistics, http://www.statistics.gov.uk/statbase/tsdlistfiles.asp", "license": "Crown copyright. Source: National Statistics website: www.statistics.gov.uk. Crown copyright material is reproduced with the permission of the Controller Office of Public Sector Information (OPSI).", "url": "http://timetric.com/series/adR4JS_USY2ljLZPehLbKQ/"}, /* more results */ ] }