vignettes/files/apis/07-04-file-safe.R

#* This is an example of an endpoint which
#* checks user input.
#* @get /
#* @query file:string*
function(query) {
  # Strip all "non-word" characters from user input
  sanitizedFile <- gsub("\\W", "", query$file)

  path <- file.path("./datasets", sanitizedFile)
  readLines(path)
}

Try the plumber2 package in your browser

Any scripts or data that you put into this service are public.

plumber2 documentation built on Jan. 20, 2026, 5:06 p.m.