Add API using plumber

This commit is contained in:
Elias Projahn 2022-12-11 19:08:22 +01:00
parent 26a209aade
commit 7f70a0c90b
5 changed files with 168 additions and 0 deletions

20
R/app.R
View file

@ -18,3 +18,23 @@ run_app <- function(host = "127.0.0.1",
port = port
)
}
#' Run the Ubigen API.
#'
#' This requires the `plumber` package to be installed.
#'
#' @param host The hostname to serve the API on.
#' @param port The port to serve the API on.
#'
#' @export
run_api <- function(host = "127.0.0.1", port = 3465) {
if (!requireNamespace("plumber", quietly = TRUE)) {
stop("Please install \"plumber\" to use this function.")
}
plumber::plumb(file = system.file(
"plumber", "ubigen", "plumber.R",
package = "ubigen"
)) |>
plumber::pr_run(host = host, port = port, docs = FALSE)
}