Creating GET and POST Endpoints
Handle path parameters, query strings, and request body parsing.
What Is Plumber?
plumber turns ordinary R functions into HTTP API endpoints using special comment annotations. Annotate a function with #* @get /path and Plumber creates a GET route that calls that function and returns its result as JSON.
Install with install.packages('plumber').
Your First GET Endpoint
A basic Plumber API lives in a file (e.g., api.R). Annotate the function with #* @get followed by the path. Plumber serializes the function's return value to JSON automatically.
# api.R
# library(plumber)
#
# #* Return a greeting
# #* @get /hello
# function() {
# list(message = 'Hello from Plumber!')
# }
#
# Start with:
# pr <- plumb('api.R')
# pr$run(port = 8000)All lessons in this course
- Introduction to Plumber and REST
- Creating GET and POST Endpoints
- Authentication and API Security
- Deploying Plumber APIs to Production