0Pricing
R Academy · Lesson

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

  1. Introduction to Plumber and REST
  2. Creating GET and POST Endpoints
  3. Authentication and API Security
  4. Deploying Plumber APIs to Production
← Back to R Academy