Skip to contents

Assembles the HTTP request structure that is common to all GitLab v4 RESTful API requests performed by this package.

Usage

api_req(
  path,
  method = c("GET", "CONNECT", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT",
    "TRACE"),
  url_params = NULL,
  body_json = NULL,
  auto_unbox = TRUE,
  base_url = funky::config_val("base_url"),
  token = funky::config_val("token"),
  max_tries = 3L
)

Arguments

path

character(1)
Endpoint path relative to the GitLab API base_url.

method

character(1)
HTTP request method. One of "GET", "CONNECT", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" or "TRACE".

url_params

list()
URL parameters added to the query string. Either NULL to omit or a named list of key-value pairs that define query parameters. Values must be scalars. To opt out of automatic conversion of non-character values to JSON strings or percent-encoding values, wrap values in I().

body_json

list()
Data to include as JSON in the HTTP request body. NULL means an empty body.

auto_unbox

logical(1)
Whether or not to automatically "unbox" length-1 vectors in body_json to JSON scalars.

base_url

character(1)
Base URL to the GitLab v4 RESTful API root.

token

character(1)
GitLab access token used for authentication. If NULL, the API request is made unauthenticated which results in HTTP 404 Not Found and other errors for non-public resources.

max_tries

integer(1)
Maximum number of request attempts in case of an HTTP error. An integerish scalar. Retries are performed using exponential backoff and jitter, see httr2::req_retry() for details.

Value

A modified HTTP request.

See also

Other common functions around GitLab's v4 RESTful API: build_url()

Examples

# let's call the `/metadata` endpoint (https://docs.gitlab.com/ee/api/metadata.html)
gitlab::api_req(path = "/metadata",
                method = "GET") |>
  httr2::req_perform() |>
  httr2::resp_body_json()
#> $version
#> [1] "18.3.0-pre"
#> 
#> $revision
#> [1] "bfe408682b0"
#> 
#> $kas
#> $kas$enabled
#> [1] TRUE
#> 
#> $kas$externalUrl
#> [1] "wss://kas.gitlab.com"
#> 
#> $kas$externalK8sProxyUrl
#> [1] "https://kas.gitlab.com/k8s-proxy"
#> 
#> $kas$version
#> [1] "18.3.0-rc1+3336d1551daceabbc23abb30207656ad2bce0940"
#> 
#> 
#> $enterprise
#> [1] TRUE
#>