Send a general request to the FRED API by specifying an endpoint and a sequence of parameters. The fredr_request() function forms and submits a request to a specified endpoint of the FRED API. The result is either the response object from httr::GET() or the response parsed as a tibble.

fredr_request(
  endpoint,
  ...,
  to_frame = TRUE,
  print_req = FALSE,
  retry_times = 3L
)

Arguments

endpoint

A string representing the FRED API endpoint of interest. See fredr_endpoints for a list of endpoint possible values. Required parameter.

...

A series of named parameters to be used in the query. Must be of the form param_key = "param_value". Acceptable parameters are endpoint-specific. See the fredr_endpoints data frame for a list of endpoints and fredr_docs() to access the web documentation for each endpoint function.

to_frame

A boolean value indicating whether or not the response should be parsed and formatted as a data frame. If FALSE, a response object is returned and further processing can be done with httr::content(). Default is TRUE.

print_req

A boolean value indicating whether or not the request should be printed as well. Useful for debugging. Default is FALSE.

retry_times

An integer indicating the maximum number of requests to attempt. Passed directly to httr::RETRY(). Default is 3.

Value

If to_frame = TRUE, a tibble containing the parsed response. If to_frame = FALSE, a response object returned directly from httr::GET().

API Documentation

FRED API

Examples

if (fredr_has_key()) { fredr_request( endpoint = "series/observations", series_id = "GNPCA", observation_start = "1990-01-01", observation_end = "2000-01-01" ) # Compare to to_frame = `FALSE` resp <- fredr_request( endpoint = "series/observations", series_id = "GNPCA", observation_start = "1990-01-01", observation_end = "2000-01-01", to_frame = FALSE ) }