-
Notifications
You must be signed in to change notification settings - Fork 6
/
plumber.R
48 lines (40 loc) · 986 Bytes
/
plumber.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# This is the hello-world plumber example with a few additions. This API is used
# to experiment with the behavior of entrypoint.R for running plumber.
library(plumber)
#* @apiTitle Entrypoint practice
#* Log requests
#* @filter logger
function(req){
cat(as.character(Sys.time()), "-",
req$REQUEST_METHOD, req$PATH_INFO, "-",
req$HTTP_USER_AGENT, "@", req$REMOTE_ADDR, "\n")
forward()
}
#* Route / to /__swagger__
#* filter route-to-swagger
function(req) {
if (req$PATH_INFO == "/") {
req$PATH_INFO <- "/__swagger__/"
}
forward()
}
#* Echo back the input
#* @param msg The message to echo
#* @get /echo
function(msg = "") {
list(msg = paste0("The message is: '", msg, "'"))
}
#* Plot a histogram
#* @png
#* @get /plot
function() {
rand <- rnorm(100)
hist(rand)
}
#* Return the sum of two numbers
#* @param a The first number to add
#* @param b The second number to add
#* @post /sum
function(a, b) {
as.numeric(a) + as.numeric(b)
}