rhttprcurlhttr

Making a GET request in R


I've been playing a little with httr and rcurl and cannot manage to translate the following curl GET request into R:

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer 31232187asdsadh23187' 'https://this.url.api.com:334/api/endpoint'

Particularly, I've been having some trouble to pass the Authorization option as I was not able to find the equivalent parameter in neither of the libraries. It might be a custom header maybe?


Solution

  • Try out the new and further improving curlconverter package. It will take a curl request and output an httr command.

    #devtools::install_github("hrbrmstr/curlconverter")
    
    library(curlconverter)
    
    curlExample <- "curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer 31232187asdsadh23187' 'https://this.url.api.com:334/api/endpoint'"
    
    resp <- make_req(straighten(curlExample))
    resp