use_microservice: Use a plumber Microservice in an R Project

Description Usage Arguments Details Value See Also Examples

View source: R/plumber-use_microservice.R

Description

Lay the infrastructure for a microservice. That includes unit test, dependency packages, configuration file, entrypoints and utility endpoint.

Usage

1
use_microservice(path = ".", overwrite = FALSE)

Arguments

path

(character) Where is the project root folder?

overwrite

(logical) Should existing destination files be overwritten?

Details

How It Works

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 *

When to Use plumber

plumber Advantages
plumber Disadvantages

Note: While plumber is single-threaded by nature, it is possible to perform parallel execution using the promises package. See links under References.

Workflow

  1. Deploy the Microservice infrastructure

microservices::use_microservice(path = ".")
remotes::install_deps()
devtools::document()
  1. Spin-up the microservice by running source("./inst/entrypoints/plumber-background.R")

  2. 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.

References

Value

No return value, called for side effects.

See Also

Other plumber microservice: add_service()

Examples

1
2
3
4
5
6
7
path <- tempfile()
use_microservice(path)

list.files(path, recursive = TRUE)

cat(read.dcf(file.path(path, "DESCRIPTION"), "Imports"))
cat(read.dcf(file.path(path, "DESCRIPTION"), "Suggests"))

microservices documentation built on June 12, 2021, 9:07 a.m.