R сантехник API - смонтированный роутер не показывает - PullRequest
0 голосов
/ 05 ноября 2019

Я пытаюсь построить API с помощью Plumber (v0.4.6). Я хочу использовать несколько файлов .R (по одному для каждой функции / конечной точки API), чтобы избежать создания одного огромного файла .R со всеми функциями. Он работает нормально только с одним файлом .R, используя:

pr <- plumb("api/v1/plumber.R")
pr$run()

Но когда я пытаюсь разделить файл сантехника на два отдельных файла, смонтированные конечные точки не показывают:

root <- plumber$new("api/v1/plumber.R")
test <- plumber$new("api/v1/fct1.R")

root$mount("/test", test)
root$run()

Это странно, потому что root$mounts показывает все конечные точки, а API показывает только корневые (график и сумма):

# Plumber router with 2 endpoints, 5 filters, and 1 sub-router.
# Call run() on this object to start the API.
├──[queryString]
├──[postBody]
├──[cookieParser]
├──[sharedSecret]
├──[logger]
├──/plot (GET)
├──/sum (POST)
├──/test
│  │ # Plumber router with 1 endpoint, 4 filters, and 0 sub-routers.
│  ├──[queryString]
│  ├──[postBody]
│  ├──[cookieParser]
│  ├──[sharedSecret]
│  └──/test8 (GET)

Вот код двух файлов:

  • водопроводчик.R
library(plumber)

#* @apiTitle Plumber Example API

#* 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)
}
  • fct1.R:
#* Echo back the input
#* @param msg The message to echo
#* @get /test8
function(msg = "") {
  list(msg = paste0("The message is: '", msg, "'"))
}

Спасибо за помощь.

...