Skip to content
Back to skills

Plumber

ASecurity

R plumber package for REST APIs. Use for creating web APIs from R functions.

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added June 5, 2026
dataapisecurity

Works with

  • api

Security analysis

A100/100

Scanned June 5, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill plumber --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Plumber?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Plumber
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-plumber/badge)](https://www.skillsdirectory.com/skills/leolin990405-plumber)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: plumber
description: R plumber package for REST APIs. Use for creating web APIs from R functions.
---

# plumber

REST APIs from R functions.

## Basic API

```r
# plumber.R
library(plumber)

#* @get /hello
function() {
  list(message = "Hello, World!")
}

#* @get /echo
#* @param msg The message to echo
function(msg = "") {
  list(message = msg)
}

#* @post /sum
#* @param a First number
#* @param b Second number
function(a, b) {
  list(result = as.numeric(a) + as.numeric(b))
}
```

## Run API

```r
library(plumber)

# Run
pr("plumber.R") %>%
  pr_run(port = 8000)

# With host
pr("plumber.R") %>%
  pr_run(host = "0.0.0.0", port = 8000)
```

## HTTP Methods

```r
#* @get /resource
function() { }

#* @post /resource
function() { }

#* @put /resource/{id}
function(id) { }

#* @delete /resource/{id}
function(id) { }

#* @patch /resource/{id}
function(id) { }
```

## Parameters

```r
# Query parameters
#* @get /search
#* @param q Search query
#* @param limit Max results
function(q, limit = 10) {
  # ?q=term&limit=20
}

# Path parameters
#* @get /users/<id>
function(id) {
  # /users/123
}

# Request body (POST/PUT)
#* @post /users
function(req) {
  body <- req$body
  # JSON body parsed automatically
}
```

## Response Types

```r
# JSON (default)
#* @get /json
function() {
  list(data = 1:5)
}

# HTML
#* @get /html
#* @html
function() {
  "<html><body><h1>Hello</h1></body></html>"
}

# Plot
#* @get /plot
#* @serializer png
function() {
  plot(1:10)
}

#* @get /plot
#* @serializer jpeg list(quality = 90)
function() {
  plot(1:10)
}

# CSV
#* @get /data
#* @serializer csv
function() {
  mtcars
}

# Custom content type
#* @get /custom
function(res) {
  res$setHeader("Content-Type", "text/plain")
  "Plain text response"
}
```

## Filters

```r
#* @filter logger
function(req) {
  cat(req$REQUEST_METHOD, req$PATH_INFO, "\n")
  plumber::forward()
}

#* @filter auth
function(req, res) {
  if (is.null(req$HTTP_AUTHORIZATION)) {
    res$status <- 401
    return(list(error = "Unauthorized"))
  }
  plumber::forward()
}
```

## Error Handling

```r
#* @get /error
function(res) {
  tryCatch({
    stop("Something went wrong")
  }, error = function(e) {
    res$status <- 500
    list(error = e$message)
  })
}

# Global error handler
pr("plumber.R") %>%
  pr_set_error(function(req, res, err) {
    res$status <- 500
    list(error = "Internal server error")
  })
```

## CORS

```r
# Enable CORS
pr("plumber.R") %>%
  pr_set_api_spec(function(spec) {
    spec$components$securitySchemes <- list(...)
    spec
  }) %>%
  pr_run()

# Or with filter
#* @filter cors
function(req, res) {
  res$setHeader("Access-Control-Allow-Origin", "*")
  if (req$REQUEST_METHOD == "OPTIONS") {
    res$setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE")
    res$setHeader("Access-Control-Allow-Headers", "Content-Type")
    res$status <- 200
    return(list())
  }
  plumber::forward()
}
```

## OpenAPI/Swagger

```r
# Auto-generated at /__docs__/

#* @apiTitle My API
#* @apiDescription API description
#* @apiVersion 1.0.0

#* Get user by ID
#* @get /users/<id>
#* @param id:int User ID
#* @response 200 User object
#* @response 404 User not found
function(id) { }
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.