Calling Plumber APIs from Other Languages

Overview #

You can publish Plumber APIs in RStudio Connect that execute R code (or call Python code with reticulate).

Once an API is hosted in RStudio Connect, you can call it from other published applications and reports. Or you can call APIs from R, Python, Java, or other languages and systems.

Code examples #

Additional information #

API keys #

You can generate and use API keys to call APIs that have been published to RStudio Connect. Learn more about using API Keys in RStudio Connect.

Custom API URLs #

You can create a custom URL for a published API. The custom URL is appended to the server domain to form the full path to the API. Learn more about setting custom content URLs in RStudio Connect.

Environment variables #

For the sake of simplicity, the code examples set the API endpoint and API key as variables directly in the code. It is best practice to read in values such as the API endpoint and API key as environment variables, a secrets manager, or some other source that avoids hard-coding these values in your code. Learn more about using environment variables in RStudio Connect.

Authorization #

RStudio Connect allows you to set the authorization method on individual APIs that have been published. The code examples assume that you are using key-based authentication in RStudio Connect for an API that requires authorization. If your API does not require authorization, then you can omit the API key and authorization header from the code examples. Learn more about setting access controls in RStudio Connect.

Standard libraries #

As much as possible, the code examples use the standard libraries from each language to make HTTP requests. Most languages have additional frameworks or packages that can make HTTP requests in a more concise way. You can extend the provided code examples to make use of these frameworks if you prefer.