get_operations: Get operations

View source: R/operations.R

get_operationsR Documentation

Get operations

Description

Creates a list of functions from API operations definition. Names in a list are operationIDs from API.

Usage

get_operations(api, .headers = NULL, path = NULL,
  handle_response = identity)

Arguments

api

API object (see get_api)

.headers

Optional headers passed to httr functions. See add_headers documentation

path

(optional) filter by path from API specification

handle_response

(optional) A function with a single argument: httr response

Details

All functions return a response object from httr package or a value returned by handle_response function if specified. When path is defined, only operations with the specified API path root are created. Use .headers parameters to send additional headers when sending a request.

Value

A list of functions.

Handling response

If no response handler function is defined, operation functions return response object (httr package). See httr content documentation for extracting content from a request, and functions http_error and http_status how to handle http errors and error messages.

When using simple result_handlers, operations will return the content of response instead of httr response object (or handle error as exception or warning in case of error).

To handle response automatically with custom function, define a function with httr response object as argument and pass it as handle_response argument to get_operations function.

Examples

## Not run: 
# create operation and schema functions
api <- get_api(api_url)
operations <- get_operations(api)
schemas <- get_schemas(api)

# get operations which return content or stop on error
operations <- get_operations(api, handle_response = content_or_stop)

# use .headers when operations must send additional heders when sending
operations <-
  get_operations(api, .headers = c("api-key" = Sys.getenv("SOME_API_KEY"))

## End(Not run)

bergant/rapiclient documentation built on May 15, 2022, 1:17 a.m.