fredr (version 1.0.0)

fredr_request: Send a request to the FRED API

Description

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 return is either the response object from GET or the response parsed as a tibble.

Usage

fredr_request(endpoint, ..., to_frame = TRUE, print_req = FALSE)

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() access to 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 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.

Value

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

API Documentation

FRED API

Examples

Run this code
# NOT RUN {
fredr_request(
  endpoint = "series/observations",
  series_id = "GNPCA",
  observation_start = "1990-01-01",
  observation_end = "2000-01-01"
)
# Compare with to_frame = TRUE
resp <- fredr_request(
  endpoint = "series/observations",
  series_id = "GNPCA",
  observation_start = "1990-01-01",
  observation_end = "2000-01-01",
  to_frame = FALSE
)

# }

Run the code above in your browser using DataLab