Calling APIs on Connect from R
Requirements
To call APIs hosted in Connect from R, you’ll need:
- URL for the API endpoint hosted on Connect
- API key (if your API requires authorization)
R Example
You can use the httr
package in R to call APIs from Shiny applications, R Markdown reports, other Plumber APIs, or R scripts:
library(httr)
<- "https://connect.yourcompany.com/rest-api/route"
connectApiUrl <- "YfB5XBRB7slkkBSEi5qr93mWJvbpXQQy"
connectApiKey
<- GET(connectApiUrl,
resp add_headers(Authorization = paste0("Key ", connectApiKey)))
<- content(resp, "parsed")
result print(result)
You can replace the values of connectApiUrl
and connectAPIKey
with your API URL and API key from Connect.
Scope
The code examples assume that you are calling a published API in Connect that is:
- Hosted on a secure server with TLS/SSL at an HTTPS endpoint
- Using an API key to make an authorized call to an API
- Making an HTTP GET request to the API
If your use case is different, then you can modify the example code accordingly.