Mar 1, 2021
|
57 min
|
18.6k views
How to Turn R Code into a Web API with Plumber
Plumber turns R functions into HTTP endpoints. You add a comment above a function saying which path and which method it answers, and Plumber serves it as a REST API, so a model written in R can be called from Python, JavaScript, a database job or anything else that speaks HTTP. This session builds one from scratch, parses incoming JSON, generates an OpenAPI interface, and deploys it to Posit Connect. With James Blair and Barret Schloerke.
What you will learn
What an API is in this context, and why an R model benefits from being one How Plumber decorators turn a plain R function into an endpoint How to build an API one endpoint at a time, starting with a health check How to parse the body of an incoming request What OpenAPI gives you, and how the generated interface lets people try the API in a browser How serializers control what comes back, and how to switch between JSON and CSV How to deploy the finished API to Posit Connect What to think about for security, rate limits and customisation Chapters 0:00 What this session covers 1:00 Agenda 1:58 The data and the model we will serve 11:19 How Plumber works 11:31 A minimal Plumber API 16:39 Building the API endpoint by endpoint 20:39 What we are trying to reach 23:24 Parsing incoming request data 29:14 Modifying an existing API 35:24 The default API interface and OpenAPI 38:49 Summary of the pattern 41:04 Deploying the API to Posit Connect 48:19 Conclusion 50:37 Security questions 52:42 Customising the interface 53:48 Rate limits 54:34 Submitting data to the endpoint
Learn more Plumber: https://www.rplumber.io Posit Connect: https://posit.co/products/enterprise/connect/ Publishing a Plumber API to Connect: https://docs.posit.co/connect/user/plumber/
Recorded in 2020. Plumber is actively maintained and the pattern shown is current. RStudio Connect is now Posit Connect
Barret Schloerke, James Blair
plumber
rstudio
Plumber R
R Api
R Rest Api
How to Turn R Code Into an Api
Plumber Tutorial
R Model Deployment
Openapi R
Rest Api Tutorial
Posit Connect
Rstudio Connect
Serve R Model
Data Science Engineering
Posit