Skip to content

Latest commit

 

History

History
125 lines (88 loc) · 3.06 KB

README.md

File metadata and controls

125 lines (88 loc) · 3.06 KB

API for Space Cloud FaaS Engines

Installation

$ npm install space-engine-node --save

Quick Start

Create Engine Instance

const Engine = require('space-engine-node');

const engine = new Engine('my-engine');

Note: All instances with same engine name are automatically load balanced.

Register the function

engine.registerFunc('my-func', (params, auth, cb) => {
console.log('Params:', params, 'Auth', auth)
// Do something

const res = { ack: true, message: 'Function as a Service is Awesome!' }
cb('response', res)
})

Note: Enable Functions module in Space Cloud, run space-exec and nats server to be able to use it.

Classes

Engine

Class representing the Engine Interface.

Functions

Callback(type, res)

Callback to be called before returning from function.

EngineFunction(params, auth, cb)

Callback for realtime updates to the subscribed data

Engine

Class representing the Engine Interface.

Kind: global class

new Engine(engineName, opts)

Create an instance of the Engine API.

Param Type Description
engineName string Name of the engine.
opts string | Object Connection options for Nats.

Example

const Engine = require('space-engine-node');
const engine = new Engine('my-engine');

// Register function with engine
engine.registerFunc('my-func', (params, auth, cb) => {
console.log('Params:', params, 'Auth', auth)
// Do something

const res = { ack: true, message: 'Function as a Service is Awesome!' }
cb('response', res)
})

engine.registerFunc(name, func)

Register the function to FaaS Engine

Kind: instance method of Engine

Param Type Description
name string Name of the function.
func EngineFunction Function to be registered

Callback(type, res)

Callback to be called before returning from function.

Kind: global function

Param Type Description
type string Type of callback action to be performed.
res Object Data to be sent to client.

EngineFunction(params, auth, cb)

Callback for realtime updates to the subscribed data

Kind: global function

Param Type Description
params Object Params received by function.
auth Object Auth object of client. Will be undefined if request is unauthenticated.
cb Callback The callback function to be called by the function.