Skip to main content

Complex Datasets

Query complex data structures.

Click one of the examples below to learn more and deploy it.

Build an API over a JSON file
Search medical information on patients, optionally filtering by country, age or diagnosis information.

Sample usage:

/patients-json[?country=<string>&minYear=<int>&maxYear=<int>&code=<string>]

The following URL returns the patients born between 1990 and 1995 that were diagnosed with L53.3.

/patients-json?minYear=1990&maxYear=1995&code=L53.3
Build an API over an XML file
Search for a person by name.

Sample usage:

/tutorial/people-xml[?name=<person_name>]

For instance, to get the information about bob use:

/tutorial/people-xml?name=bob
Querying web services
Examples on how to perform HTTP requests, passing headers, args or authentication options.

This example shows how to make HTTP requests:

  • How to use different HTTP methods like GET, PUT, POST, DELETE, etc;
  • How to pass headers;
  • How to pass query paramenters.

Using HTTP URLs directly

Functions that read data from external locations can receive a URL. For instance, this example does an HTTP GET request on the source data.

Json.InferAndRead("http://test-data.raw-labs.com/public/authors.json")

It is equivalent to the following example:

Json.InferAndRead(Http.Get("http://test-data.raw-labs.com/public/authors.json"))

That is because HTTP URLs are converted directly to "Http.Get" requests.

However, sometimes you need to configure the HTTP request: use POST instead of GET, or pass headers or parameters. The next section describes how.

Making HTTP requests

To change HTTP method, specify headers, or pass query parameters along with other options, use the functions in the Http library.

The following example performs a POST request - using the Http.Post function - and passes a string as the HTTP POST body - using the optional argument bodyString:

String.Read(
Http.Post(
"http://somewhere/api/clients"
bodyString = """{"name": "john", "query": "account"}"""
)
)

There are functions in the Http library for each HTTP method: e.g. Http.Get for GET requests, Http.Post for POST requests, Http.Put for PUT requests, etc. Please refer to the documentation for additional details.

These functions accept the same arguments to pass headers, query parameters and other properties of the HTTP request.

Sample usage

The following example performs an HTTP request to wikidata with a SPARQL query listing cat entries. It passes query parameters (args) containing the query and uses HTTP headers (headers) to set the output format as CSV:

main() =
let query = "SELECT ?item ?birthdate ?itemLabel \n" +
"WHERE {\n" +
" ?item wdt:P31 wd:Q146. # Must be of a cat \n" +
" ?item wdt:P569 ?birthdate . # P569 : birthdate\n" +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\". } \n" +
"}",
data = Csv.Read(
Http.Get(
"https://query.wikidata.org/bigdata/namespace/wdq/sparql",
args = [{"query", query}],
headers = [{"Accept", "text/csv"}]
),
type collection(record(item: string, birthdate: string, itemLabel: string)),
skip = 1
)
in data

main()