Use a plumber Microservice in an R Project
use_microservice(path = ".", overwrite = FALSE)
path | ( |
---|---|
overwrite | ( |
No return value, called for side effects.
Given a path
to a folder
When use_microservice(path = ".")
is called
Then the function creates the following files:
tests/testthat/test-endpoint-plumber-utility.R inst/configurations/plumber.yml inst/endpoints/plumber-utility.R inst/entrypoints/plumber-background.R inst/entrypoints/plumber-foreground.R
And updates the following files:
tests/testthat/helpers-xyz.R
And adds the following packages to the DESCRIPTION file:
type | package | version |
Suggests | config | * |
Suggests | httptest | * |
Suggests | httr | * |
Imports | jsonlite | * |
Suggests | pkgload | * |
Suggests | plumber | >= 1.0.0 |
Imports | purrr | * |
Suggests | testthat | * |
Suggests | usethis | * |
Suggests | promises | * |
Suggests | future | * |
plumber
A Single user/machine applications.
Scheduled tasks. For example, you could use AirFlow with HTTP Operators to automate processes.
plumber
AdvantagesComes with familiar way to document the microservice endpoint.
Maturing package that comes with documentation, examples and support.
plumber
DisadvantagesRuns on a single thread. That means that parallel algorithms such as random forest, can only be run on one core.
Serves only one caller at a time.
Can’t make inward calls for other services, That means plumber can’t
be
re-entrant.
For example, if a microservice has three endpoints,read_table
,
write_table
, and orchestrator
, where the orchestrator
reads a
data table, transforms it, and writes it back, then the
orchestrator
can’t make inwards calls via HTTP to read_table
and
write_table
.
Note: While plumber
is single-threaded by nature, it is possible
to perform parallel execution using the promises
package. See links
under References.
Deploy the Microservice infrastructure
microservices::use_microservice(path = ".") remotes::install_deps() devtools::document()
Spin-up the microservice by running
source("./inst/entrypoints/plumber-background.R")
Run the microservice unit-test by pressing Ctrl+Shift+T on Windows
Congratulations! You have added a microservice to your application and tested that it works.
Other microservice utilities:
add_service()
#> [1] "DESCRIPTION" #> [2] "inst/configurations/plumber.yml" #> [3] "inst/endpoints/plumber-utility.R" #> [4] "inst/entrypoints/plumber-background.R" #> [5] "inst/entrypoints/plumber-foreground.R" #> [6] "tests/testthat/helpers-xyz.R" #> [7] "tests/testthat/test-endpoint-plumber-utility.R"#> jsonlite, #> purrr#> config, #> httptest, #> httr, #> pkgload, #> plumber (>= 1.0.0), #> testthat, #> usethis, #> promises, #> future