micro / micro-js

Micro JS Client

Home Page:https://www.npmjs.com/package/micro-js-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Micro JS Client

The JS client for the Micro Platform.

View on NPM

Usage

Installation:

npm install --save micro-js-client

Request

Make a standard http request

const micro = require('micro-js-client');

new micro.Client({ token: 'MICRO_API_TOKEN' })
  .call('helloworld', 'call', {"name": "Alice"})
  .then((response) => {
    console.log(response);
  });

The output will be:

{ message: 'Hello Alice' }

Streaming

Make a websocket streaming request

const micro = require("micro-js-client")

new micro.Client({ token: 'MICRO_API_TOKEN' })
  .stream("helloworld", "stream", {"name": "Alice", "messages": 10})
  .then(stream => {
	stream.recv(msg => {
		console.log("message received: ", msg)
	})
}).catch(e => {
	console.log(e)
})

setInterval(() => {}, 5000);

Above example will output:

message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }
message received:  { message: 'Hello Alice' }

Format

The JS client uses the Micro API to make requests. Just pass service, endpoint and the json request.

The call /helloworld/call routes to the service helloworld and endpoint Call. So just do:

micro.Client.call("helloworld", "call", {"name": "Alice"})

About

Micro JS Client

https://www.npmjs.com/package/micro-js-client

License:Apache License 2.0


Languages

Language:TypeScript 94.9%Language:JavaScript 5.1%