Learn R Programming

microservices (version 0.2.0)

add_service: Add a Service Route to the Microservice

Description

Expose additional set of services on a separate URL.

Usage

add_service(path = ".", name, overwrite = FALSE)

Value

No return value, called for side effects.

Arguments

path

(character) Where is the project root folder?

name

(character) what is the service route name? For example, if name = "repository" then the set of services would become available at http://127.0.0.1:8080/repository/.

overwrite

(logical) Should existing destination files be overwritten?

Details

Lay the infrastructure for an additional set of services. That includes adding a unit test, adding an endpoint, and extending the entrypointy.<div class="alert alert-warning"> **Note:** `add_service` adds a service to pre-existing plumber microservice which you could deploy by calling `use_microservice`. </div>

How It Works

Given a path to a folder and a service name

When add_service(path, name) is called

Then the function creates the following files:

tests/testthat/test-endpoint-plumber-{route_name}.R
inst/endpoints/plumber-{route_name}.R

And updates the following files:

inst/entrypoints/plumber-foreground.R

When to Use

In scenarios where services are thematically linked to each other. Examples for themes that should be mounted separately:

  • 'forecasting' and 'anomaly detection'

  • 'user' and 'business'

See Also

Other plumber microservice: use_microservice()

Examples

Run this code
path <- tempfile()
dir.create(path, showWarnings = FALSE, recursive = TRUE)
use_microservice(path)

add_service(path, name = "repository")

list.files(path, recursive = TRUE)

Run the code above in your browser using DataLab