Learn R Programming

eudata (version 0.1.3)

get_content: Get content from the API

Description

This function retrieves the content from the API and saves it to a file if `save_to_file` is TRUE.

Usage

get_content(
  api,
  end_point,
  save_to_file = FALSE,
  dest = if (save_to_file) fs::path_file(end_point) else NULL
)

Value

A `httr2` response object. The content retrieved from the API is either the `body` of response or the path to the file when `save_to_file` is TRUE.

Arguments

api

An endpoint to the dataset.

end_point

A character vector of the endpoint to retrieve content from.

save_to_file

A logical value indicating whether to save the content to a file

dest

A character vector specifying the destination file path. If `save_to_file` is TRUE, this should be a valid file path.

Examples

Run this code
api <- get_topic("Postal")
files <- get_latest_files(api)$csv
file_to_download <- grep("_4326", files, value=TRUE)
response <- get_content(
  api,
  file_to_download,
  save_to_file = TRUE,
  dest = fs::file_temp(ext = "csv")
)
response$body

Run the code above in your browser using DataLab