1#
2# This is a Plumber API. In RStudio 1.2 or newer you can run the API by
3# clicking the 'Run API' button above.
4#
5# In RStudio 1.1 or older, see the Plumber documentation for details
6# on running the API.
7#
8# Find out more about building APIs with Plumber here:
9#
10#    https://www.rplumber.io/
11#
12
13library(plumber)
14
15#* @apiTitle Plumber Example API
16
17#* Echo back the input
18#* @param msg The message to echo
19#* @get /echo
20function(msg=""){
21  list(msg = paste0("The message is: '", msg, "'"))
22}
23
24#* Plot a histogram
25#* @png
26#* @get /plot
27function(){
28  rand <- rnorm(100)
29  hist(rand)
30}
31
32#* Return the sum of two numbers
33#* @param a The first number to add
34#* @param b The second number to add
35#* @post /sum
36function(a, b){
37  as.numeric(a) + as.numeric(b)
38}
39
40