Skip to content

Plumber

Use prLog to run a plumber API that logs requests, their paths, latency, and more.

Create a standard plumber API file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#* Increment a counter
#* @get /
function() {
  return("Hello titan!")
}

#* Plot a histogram
#* @serializer png
#* @get /plot
function() {
  rand <- rnorm(100)
  hist(rand)
}

Use prLog.

1
2
3
4
library(plumber) 

log::prLog("test.R") %>%  
  pr_run() 

If you are using a package that already modifies the plumber object (e.g.: titan) and cannot use prLog, you can use prWithLog instead.

1
2
3
titan::prTitan("test.R") %>%  
  prWithLog() %>% 
  pr_run()