Skip to contents

A base class providing common methods for making REST API calls.

Usage

rest_api(
  base_url,
  url_template,
  suffix,
  status_codes,
  delay,
  cache = NULL,
  query_column,
  ...
)

Arguments

base_url

(character) The base URL of the API.

url_template

(character) A template describing how the URL should be constructed from the base URL and input parameters. e.g. <base_url>//<input_item>/<search_term>/json.The url will be constructed by replacing the values enclosed in <> with the value from corresponding input parameter of the rest_api object.

suffix

(character) A suffix appended to all column names in the returned result.

status_codes

(list) Named list of status codes and function indicating how to respond. Should minimally contain a function to parse a successful response for status code 200. Any codes not provided will be passed to httr::stop_for_status().

delay

(numeric, integer) Delay in seconds between API calls.

cache

(annotation_database, NULL) A struct cache object that contains parsed responses to previous api queries. If not using a cache then set to NULL. The default is NULL.

query_column

(character) The name of a column in the annotation table containing values to search in the api call.

...

Additional slots and values passed to struct_class.

Value

A rest_api object with the following output slots:

updated(annotation_source) The annotation_source after adding data returned by the API.

Inheritance

A rest_api object inherits the following struct classes:

[rest_api] -> [model] -> [struct_class]

Examples

M = rest_api( base_url = "V1", url_template = character(0),
query_column = character(0), cache = NULL, status_codes = list(),
delay = 0.5, suffix = "_rest_api")