Skip to content

matter-in-motion/mm-client-browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matter In Motion. Browser client

NPM Version NPM Downloads

Browser client for matter in motion framework

Installation

npm i mm-client-browser

Usage

import MM from 'mm-client-browser';
import HTTP from 'mm-client-browser/http';

const mm = new MM({
  host: 'localhost:3000',
  tls: false,
  log: (level, ...args) => console.log(level, ...args)
});

mm.addTransport(HTTP());
mm.init(() => {
  console.log('ready');
  // example from post resource
  mm.call('post.get', { })
});

Methods

constructor(settings)

Creates the matter-in-motion client. Settings are:

  • host — string, the host name for the api server.
  • tls — boolean, default true. Should client use secure connection.
  • serializer — mime string, default 'application/json'. Data type mime that is expected from the server.
  • api — string, path, default '/api'. Api path.
  • log — function. Function that will be used to log.

addTransport(transport)

Adds a transport.

setTransport(name)

Sets default transport.

setAuth(controller)

Sets the authentication controller.

isAuthenticated()

Returns null if no authentication controller defined. Othewise calls the this.auth.isAuthenticated method and returns the result.

init(callback)

Inits all the transports. Initis the authentication controller if present. Calls callback.

call(call, body, options, cb)

Calls the api. Similar calls will be throttled.

will(call, fn)

Adds will call hook.

did(call, fn)

Adds did call hook.

License: MIT

© velocityzen