1.0.3 • Published 4 years ago

@openremote/rest v1.0.3

Weekly downloads
1
License
AGPL-3.0-or-later
Repository
-
Last release
4 years ago

@openremote/rest

NPM Version Linux Build Test Coverage

ES6 modules for connecting to an OpenRemote Manager as well as utilities for performing common tasks.

The default export is a singleton of type RestApi that can be used to communicate with the OpenRemote Manager REST API. It uses an axios client to perform the requests and it contains strongly typed definitions for each OpenRemote Manager REST API endpoint (JAX-RS resource).

Install

npm i @openremote/rest
yarn add @openremote/rest 

Usage

For a full list of properties, methods and options refer to the TypeDoc generated documentation.

If used in conjunction with @openremote/core and the Manager init method has been called then the default export will be ready to use, the endpoints can be accessed via the RestApi api property and each JAX-RS resource defined in the OpenRemote Manager is also defined with the same name in the RestApi object.

import openremote from "@openremote/core";
import rest from "@openremote/rest";

openremote.init({
    ...
}).then((success) => {
    if (success) {
        let assetQuery = ...;
        let response = await rest.api.AssetResource.queryAssets(assetQuery);
        let assets = response.data;
        
        // Do something with the assets
    } else {
        // Something has gone wrong
    }
});

It is possible to add additional request interceptors by calling the addRequestInterceptor method, it is also possible to access the AxiosInstance by calling the axiosInstance property.

It is also possible to instantiate the RestApi object on demand but note you will need to ensure the Authorization header is correctly set if calling secure endpoints on the OpenRemote Manager REST API.

import {RestApi} from "@openremote/rest";

let rest = new RestApi();
rest.setTimeout(10000);
rest.addRequestInterceptor(...);
rest.initialise();

Supported Browsers

The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also supported.

License

GNU AGPL