Open source solutions for exposing R as API endpoints
We are going to start off by first showing how to expose R as an API endpoint via the plumber package. The plumber package and its associated documentation can be found at the following URL: https://www.rplumber.io/index.html.
The first thing we will do is build out a very simple single-argument API to obtain the histogram of a standard normal distribution. Let’s take a look at the code; we will then discuss what is happening inside of it:
#* Plot out data from a random normal distribution #* @param .mean The mean of the standard normal distribution #* @get /plot #* @serializer png function(.mean) { mu <- as.numeric(.mean) hist(rnorm(n = 1000, mean = mu, sd = 1)) }
The lines starting with #*
are comments. In the plumber API, these comments are special and are used for documentation. They describe what the API endpoint does and provide information about the parameters. The first comment introduces...