Skip to content

Clients

Once you’ve deployed your service, you can connect any number of client NPM projects to it.

Client Module

Connecting a client to a service involves generating client code called a Client Module.

The client module contains:

  • The classes and functions your client code can use to access the service.
  • A user key used to authenticate the client code to the Roli platform at runtime.
  • The version number of the deployed service.
  • The URL of the Roli platform installation.

Generating a client module

To create a client module for your service, use the generate-client command:

Terminal window
$ roli generate-client --project /path/to/my/npm/project my-service-name

The client module will be generated in the .roli/bindings/<service-name> directory. It is automatically set as a dependency in the client project’s package.json.

Supressing build integration

Optionally, you can generate the client module without requiring a dependency installation:

Terminal window
$ roli generate-client --project /path/to/my/npm/project my-service-name --no-install

Importing the client module

The client module is unique to the service and will be named <service-name>-service. The client module can be imported just like any other NPM module dependency.

Using CommonJS

// Client code
const {MyApi, MyData} = require('<service-name>-service');

Using ESM import

// Client code
import {MyApi, MyData} from '<service-name>-service';