0.1.0 • Published 6 years ago

rapidm2m-api v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

rapidM2M API

This module is designed to use with the API of a rapidM2M server, but can also be used from every node.js script.

Features

  • 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 API
  • Based on axios client
  • Integrated URL encoding of path string

Installing

Using npm: $ npm install rapidm2m-api

API

For convenience aliases are provided for the most common request methods.

get

get(path[, query])

put

put(path, data)

post

post(path, data)

del

del(path, data)

request

request(config) Internally, all requests are processed in the API function request. See the section Request config.

Request config

When the function requestis 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 for all other config options.

Example with internal authentication (use in BLO scripts)

//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);  
 }  
})();

Example with provided authentication

import BAPI from 'rapidm2m-api/bapi';  
  
//create instance  
let bapi = new BAPI({
  'username': '{user}',
  'password': '{pwd}'
});