apicall: Assemble a web API call URL

Description Usage Arguments Details Value Examples

View source: R/apicall.R

Description

Assembles an arbitrary web API call URL from a base URL and query string terms. Returns a URL as a string.

Usage

1
2
apicall(baseurl, path = "", params = NULL, queryterms = NULL,
  apikey = NULL, format = NULL)

Arguments

baseurl

string. The base URL to which an additional path and additional query terms may be appended. If baseurl does not begin with 'http://' or 'https://', then 'https://' is prepended.

path

string (optional). An additional path to be appended to the base URL before the "?" separator and query terms.

params

list (optional). A list of query terms in the form list(key1=value1,key2=value2,...)

queryterms

character vector (optional). Vector of query terms passed as strings in the form c("key1[operator]value1", "key2[operator]value2", ...). This is useful if the API allows operators other than =, for example http://foo.foo/query?count>=20.

apikey

string. (optional). An API key. The API key can also be passed with params or queryterms.

format

string. (optional). A reponse format given as an extension. If none is specified, the API's default reponse format will be requested. Many API's use JSON as the default. Example formats might include "csv", "xlm", etc. The format will be appended to the API call as a file extension.

Details

A web API call consitst of a base URL with optional additional path, followed by a "?" separator and query terms separated by the "&" separator.

Query terms are in the form [key][operator][value], most commonly [key]=[value].

apicall() uses the baseurl argument, if provided, as the base URL. path is appended to baseurl before the "?" separator. Queries are built from a list of key-value pairs passed to the param argument, and/or a character vector of query terms (conditions) passed to the queryterms argument. An API Key, if required, can be set via the apikey argument, or passed to param or queryterms. Any combination of queryterms, param and apikey can be used.

apicall() automatically replaces spaces with %20 in the final URL.

Value

string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
apicall(baseurl="http://foo.com/", path="list")

p <- list(author="Davy Jones",format="book")
apicall(baseurl="http://foo.com/", path="search", params=p)

q <- c("author=Davy Jones","year>=1980")
apicall(baseurl="http://foo.com/", path="search", queryterms=q)

apicall(baseurl="http://foo.com/search", params=p, queryterms="year>=1980", apikey="123abc")

## End(Not run)

allopole/tycho2 documentation built on Dec. 26, 2019, 2:48 a.m.