rapidm2m-api
Version:
Promise based HTTP client to access the rapidM2M API
66 lines (55 loc) • 2.17 kB
Markdown
is designed to use with the API of a rapidM2M server, but can also be used from every node.js script.
* Integrated authentication for Backend Logic scripts that are written in rapidM2M Studio
* Authentication against the rapidM2M Backend API from outside of a Backend Logic script is also supported
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
* Based on [axios](https://www.npmjs.com/package/axios) client
* Integrated URL encoding of path string
Using npm:
`$ npm install rapidm2m-api`
For convenience aliases are provided for the most common request methods.
`get(path[, query])`
`put(path, data)`
`post(path, data)`
`del(path, data)`
`request(config)`
Internally, all requests are processed in the API function `request`. See the section [Request config](
When the function `request`is used, the config is forwarded to the internal axios client. The only exception is the field `path`, which will internally be URL encoded and then placed in the config as `url`.
See the [axios docs](https://www.npmjs.com/package/axios#request-config) for all other config options.
```javascript
//specific module for BLO scripts
import BAPI from 'rapidm2m-api/bapi-blo';
//create instance with default settings
let bapi = new BAPI();
(async () => {
try {
//only use 'data' from the result. The full result from the axios client is also available.
let {data: customers} = await bapi.get(['customers']);
for (let customer of customers) {
//change every customer's properties...
await bapi.put(['customers', customer._uid], {});
}
} catch (e) {
console.error(e);
}
})();
```
```javascript
import BAPI from 'rapidm2m-api/bapi';
//create instance
let bapi = new BAPI({
'username': '{user}',
'password': '{pwd}'
});
```
This module