httpRequest: Submit an HTTP request

httpRequestR Documentation

Submit an HTTP request

Description

This function uses curlPerform to carry out all low-level HTTP requests (i.e., API calls), converting all input and output to/from JSON as specified.

Usage

httpRequest(
  url,
  method = c("GET", "POST", "PUT", "DELETE"),
  content,
  httpheader = c(Accept = "application/json", `Content-Type` = "application/json"),
  curl
)

Arguments

url

A character string specifying the URL to which an HTTP request will be submitted

method

A character string specifying the method to be used to submit the HTTP request

content

An optional variable specifying the content to be uploaded during a POST or PUT request

httpheader

A character vector specifying the httpheader CURLOption to be used; defaults to Accept='application/json' and Content-Type='application/json'

curl

A CURLHandle object

Details

curlPerform is used in place of getURL (which does not collect the HTTP header) and getURLContent (which does not return the HTTP response body in the event of an HTTP error)

Value

If an HTTP error was encountered, a simpleError object is returned containing a character vector that consists of an HTTP status line, followed by the HTTP response body (if it exists). Otherwise:

  • If the Content-Type attribute of the HTTP response body is set to 'application/json', the response body is converted from JSON to an R object, and that object is returned.

  • If that attribute is set to anything else (or does not exist), the HTTP response body itself is returned.

Author(s)

Adam C. Gower agower@bu.edu


agower/GeneHive documentation built on April 14, 2022, 5:08 a.m.