get_content: Get content from the API

View source: R/api.R

get_contentR Documentation

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
)

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.

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.

Examples

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

eudata documentation built on Aug. 8, 2025, 7:22 p.m.