Skip to contents

[Experimental]

Usage

ru_http_request(
  verb,
  url,
  path = NULL,
  query = NULL,
  accept = "application/json",
  headers = NULL,
  un = NULL,
  pw = NULL,
  body = NULL,
  encode = NULL,
  dest = NULL,
  overwrite = TRUE,
  terminate_on = NULL,
  retries = get_retries()
)

Arguments

verb

(character) The HTTP verb, e.g. "GET", "POST".

url

(character) The base URL of the ODK Central server, or the complete request URL if path is NULL.

path

(character) The request path, e.g. "v1/projects". If NULL, url is used as the complete request URL. Default: NULL.

query

(list) Optional query string parameters. Default: NULL (no query string).

accept

(character) The Accept header value. Default: "application/json". Set to NULL to send no Accept header.

headers

(character) Optional extra headers as a named character vector, e.g. c("X-Extended-Metadata" = "true"). Default: NULL (no extra headers).

un

(character) The ODK Central username for basic authentication. Default: NULL (no authentication).

pw

(character) The ODK Central password for basic authentication. Default: NULL (no authentication).

body

The request body. Default: NULL (no body).

encode

(character) The body encoding: "json" sends JSON, anything else sends raw bytes. Default: NULL (no body).

dest

(character) A local file path to stream a download to. Default: NULL (no streaming, the response is kept in memory).

overwrite

(lgl) Whether to overwrite dest if it exists. Only used with dest. Default: TRUE.

terminate_on

(numeric) HTTP status codes that stop retries immediately. Default: NULL (only non-transient statuses stop retries).

retries

The number of attempts to retrieve a web resource.

This parameter is given to RETRY(times = retries).

Default: 3.

Value

The httr response object, unmodified.

Details

This is the centralised request helper for ruODK. It builds an httr2 request from plain data (verb, path, query, headers, credentials, body) and returns the httr2 response unchanged, so yell_if_error() and the httr2::resp_body_*() parsers keep working downstream. The full URL keeps the legacy query semantics on purpose: query values that callers pre-encode (for example entitylist_download()'s $filter) must not be encoded twice.

Examples

if (FALSE) { # \dontrun{
# See vignette("setup") for setup and authentication options
# ruODK::ru_setup(svc = "....svc", un = "me@email.com", pw = "...")

resp <- ruODK:::ru_http_request(
  "GET",
  url = get_test_url(),
  path = "v1/projects",
  un = get_test_un(),
  pw = get_test_pw()
)

httr2::resp_status(resp)
} # }