Plumber API Example, slightly modified to run on Cloud Foundry (CF).
Note the following important nuances:
- The host should be set as "0.0.0.0" in the pr$run function in startscript.R
- The port is best set by including PORT <- as.numeric( Sys.getenv('PORT') ) and then supplying PORT as the argument in the pr$run function in startscript.R
To push this app to your CF environment, run the following command after establishing an API endpoint:
cf push rplumber -b https://github.com/cloudfoundry/r-buildpack.git
An example API is hosted live on a Cloud Foundry environment here. To test the API is working try typing the following into a web browser:
https://rplumber.apps.pcfone.io/echo?msg=DataScienceonPCF!
Also try typing the following simple summing function in a terminal window (return sum of 5 and 6):
curl --data "a=5&b=6" "https://rplumber.apps.pcfone.io/sum"