Hi
I have created some R APIs and to use in a docker container.
However, the first API is the only one that works.
For the second api, we get an error could not find function.
Is it possible to combine multiple api functions in one plumber file?
Is there a better way that what Im trying to do?
Here is an example of plumber.r
#* @apiTitle test
#* @apiDescription test
source("/code/api1.R")
source("/code/api2.R")
## ---- filter-logger
#* Log some information about the incoming request
#* @filter logger
function(req){
cat(as.character(Sys.time()), "-",
req$REQUEST_METHOD, req$PATH_INFO, "-",
req$HTTP_USER_AGENT, "@", req$REMOTE_ADDR, "\n")
forward()
}
#* @post /api1
#* @param Dataframe
function(req,res) {
data <- tryCatch(jsonlite::parse_json(req$postBody, simplifyVector = TRUE),
error = function(e) NULL)
if (is.null(data)) {
res$status <- 400
return(list(error = "No data submitted "))
}
req$results <- api1_function(data)
}
#* @post /api2
#* @param Dataframe
function(req,res) {
data <- tryCatch(jsonlite::parse_json(req$postBody, simplifyVector = TRUE),
error = function(e) NULL)
if (is.null(data)) {
res1$status <- 400
return(list(error = "No data submitted"))
}
req$results <- api2_function(data)
}
Entrypoint file
library(plumber)
r <- plumb("/code/plumber.R")
r$run(host='0.0.0.0', port=8000, swagger=TRUE)
Would really appreciate some help on this.
Thanks