-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplumber.R
60 lines (52 loc) · 1.09 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
#
# This is a Plumber API. You can run the API by clicking
# the 'Run API' button above.
#
# Find out more about building APIs with Plumber here:
#
# https://www.rplumber.io/
#
library(plumber)
#* @apiTitle Plumber Swagger Experiments API
#* 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 request
forward()
}
#* Filter to practice preempt
#* @filter fail
function(req) {
if (grepl("swagger", tolower(req$PATH_INFO))) {
forward()
}
list(
msg = "You didn't make it"
)
}
#* Echo back the input
#* @preempt fail
#* @param msg The message to echo
#* @get /echo
function(msg = "") {
list(msg = paste0("The message is: '", msg, "'"))
}
#* Plot a histogram
#* @preempt fail
#* @png
#* @get /plot
function() {
rand <- rnorm(100)
hist(rand)
}
#* Return the sum of two numbers
#* @preempt fail
#* @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)
}