Search code examples
rapiresthttr

How would I connect to this API from rapidapi in R?


I've never connected to an API in R and I am a bit confused on how to just approach it. I am looking to pull flight price data from rapid-api (I have an account) into my R console. Here is the API (to my knowledge) on their website, what script would I start with to connect to this API?

enter image description here


Solution

  • The httr package has a GET() and a add_header() function, that let you replicate the functionality I see in the "Code Snippets" tab.

    Can't test it, but it should look something like this:

    library(httr)
    
    GET(
      url = rapidapi_url,
      config = list(x-rapidapi-key = API_KEY,
                    x-rapidapi-host = HOST_URL,
                    useQueryString = TRUE),
      inboundpartialdate = "2019-12-01"
    )