I'm trying to update my code to pull data from an API. I'm using currently the httr package, but it has been deprecated, so I want to replace my code using the httr2 package. I'm trying to download data in a data frame format. The code using httr is:
api_response <- httr::GET(url, httr::authenticate(user_name, password))
data <- httr::content(api_response, type="text/csv")
data is a data frame. How do I get the same result using httr2?
I've tried:
api_response <- request(url) %>%
req_auth_basic(user_name,
password) %>%
req_perform()
and I get a httr2_response object and no errors. I don't know how to perform the next step of downloading the data in a data frame format.
As already stated in an httr2 github issue, you want to extract the contents as a string and parse it yourself explicitly with
readr::read_csvThis was basically what
httrwas doing under the hood