rest: REST API Access

Description Usage Arguments Value Author(s) See Also

View source: R/package.R

Description

Minimal wrapper to work with REST APIs.

This is an extremely minimal client. You need to know the API to be able to use this client. All this function does is:

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
rest(
  endpoint,
  ...,
  per_page = NULL,
  .token = NULL,
  .destfile = NULL,
  .overwrite = FALSE,
  .api_url = NULL,
  .method = "GET",
  .limit = NULL,
  .accept = "application/vnd.github.v3+json",
  .send_headers = NULL,
  .progress = TRUE
)

Arguments

endpoint

API endpoint. Must be one of the following forms:

  • METHOD path, e.g. GET /rate_limit,

  • path, e.g. /rate_limit,

  • METHOD url, e.g. GET https://api.domain.com/v1/rate_limit,

  • url, e.g. https://api.domain.com/v1/rate_limit.

If the method is not supplied, will use .method, which defaults to "GET".

...

Name-value pairs giving API parameters. Will be matched into endpoint placeholders, sent as query parameters in GET requests, and as a JSON body of POST requests. If there is only one unnamed parameter, and it is a raw vector, then it will not be JSON encoded, but sent as raw data, as is. This can be used for example to add assets to releases. Named NULL values are silently dropped, and named NA values trigger an error.

per_page

Number of items to return per page. If omitted, will be substituted by max(.limit, 100) if .limit is set, otherwise determined by the API (never greater than 100).

.token

Authentication token. Defaults to GITHUB_PAT or GITHUB_TOKEN environment variables, in this order if any is set. See rest_token() if you need more flexibility, e.g. different tokens for different GitHub Enterprise deployments.

.destfile

path to write response to disk. If NULL (default), response will be processed and returned as an object. If path is given, response will be written to disk in the form sent.

.overwrite

if .destfile is provided, whether to overwrite an existing file. Defaults to FALSE.

.api_url

Github API url (default: https://api.github.com). Used if endpoint just contains a path. Defaults to GITHUB_API_URL environment variable if set.

.method

HTTP method to use if not explicitly supplied in the endpoint.

.limit

Number of records to return. This can be used instead of manual pagination. By default it is NULL, which means that the defaults of the GitHub API are used. You can set it to a number to request more (or less) records, and also to Inf to request all records. Note, that if you request many records, then multiple GitHub API calls are used to get them, and this can take a potentially long time.

.accept

The value of the Accept HTTP header. Defaults to "application/vnd.github.v3+json" . If Accept is given in .send_headers, then that will be used. This paramter can be used to provide a custom media type, in order to access a preview feature of the API.

.send_headers

Named character vector of header field values (except Authorization, which is handled via .token). This can be used to override or augment the default User-Agent header: "https://github.com/r-lib/gh".

.progress

Whether to show a progress indicator for calls that need more than one HTTP request.

Value

Answer from the API as a rest_response object, which is also a list. Failed requests will generate an R error. Requests that generate a raw response will return a raw vector.

Author(s)

Maintainer: Gábor Csárdi csardi.gabor@gmail.com [contributor]

Authors:

See Also

Useful links:


coatless/rest documentation built on May 27, 2020, 12:03 a.m.