opentmi-jsclient

0.11.0 • Public • Published

opentmi-jsclient

npm version CircleCI Coverage Status JavaScript Style Guide License badge

Promise based OpenTMI javascript client for node.js and browser. Extendable for custom API's provided by opentmi addons.

Requirements

Documentation

API documentation

Installation

npm i opentmi-jsclient

Build

to build minified version to dist -folder run:

> npm run build

build api documentations

> npm run doc

Note: all available commands are visible when you run: npm run

Sample

Node.js

const {Authentication, Transport, Resources} = require('opentmi-client');
const transport = new Transport('http://localhost:3000')
const auth = new Authentication(transport);
auth
  .login('user@mail.com', 'password')
  .then(() => transport.connect())
  .then(() => {
      const collection = new Resources(transport);
      return collection.find()
        .haveTag('fantastic')
        .exec()
        .then(resources => resources[0])
        .then(resource => {
          return resource
            .name('new name')
            .save();
        });
  })

Browser

<script src="dist/opentmi-client.js"></script>
<script>
const {Authentication, Transport} = opentmiClient;
const transport = new Transport('http://localhost:3000')
const auth = new Authentication(transport);
auth
  .login('user@mail.com', 'password')
  .then(() => transport.connect())
</script>

Note: see more examples from sample -folder.

Customize

It is easy to create support for custom API's. See example below:

class CustomAPI {
  constructor(transport) {
    this._transport = transport;
  }
  some() {
    debug('attempt to get something from custom addon api');
    return this._transport
      .get('/addon-api')
      .then(response => response.data);
  }
}
const customApi = new CustomAPI(transport);
customApi.some().then(data => console.log(data));

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i opentmi-jsclient

Weekly Downloads

1

Version

0.11.0

License

MIT

Unpacked Size

9.09 MB

Total Files

452

Last publish

Collaborators

  • jussiva