https://github.com/opentmi/opentmi-jsclient
OpenTMI javascript client for backend&browser
https://github.com/opentmi/opentmi-jsclient
javascript-client opentmi
Last synced: 25 days ago
JSON representation
OpenTMI javascript client for backend&browser
- Host: GitHub
- URL: https://github.com/opentmi/opentmi-jsclient
- Owner: OpenTMI
- License: mit
- Created: 2017-09-30T08:32:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-26T10:36:55.000Z (about 2 months ago)
- Last Synced: 2025-04-04T07:23:07.793Z (about 2 months ago)
- Topics: javascript-client, opentmi
- Language: JavaScript
- Homepage: https://opentmi.github.io/opentmi-jsclient
- Size: 2.61 MB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 42
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
opentmi-jsclient
[](https://www.npmjs.com/package/opentmi-jsclient)
[](https://circleci.com/gh/OpenTMI/opentmi-jsclient/tree/master)
[](https://coveralls.io/github/OpenTMI/opentmi-jsclient?branch=master)
[](https://standardjs.com)
[](https://img.shields.io)Promise based [OpenTMI](https://github.com/opentmi/opentmi) javascript client for node.js and browser.
Extendable for custom API's provided by opentmi addons.## Requirements
* [opentmi backend](https://github.com/opentmi/opentmi)## Documentation
[API documentation](https://opentmi.github.io/opentmi-jsclient/)## 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
```javascript
const {Authentication, Transport, Resources} = require('opentmi-client');
const transport = new Transport('http://localhost:3000')
const auth = new Authentication(transport);
auth
.login('[email protected]', '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
```javascriptconst {Authentication, Transport} = opentmiClient;
const transport = new Transport('http://localhost:3000')
const auth = new Authentication(transport);
auth
.login('[email protected]', 'password')
.then(() => transport.connect())```
**Note:** see more examples from [sample](sample) -folder.
### Customize
It is easy to create support for custom API's. See example below:
```javascript
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](LICENSE)