serverless/event-gateway-sdk

Name: event-gateway-sdk

Owner: Serverless

Description: Event Gateway JavaScript SDK

Created: 2018-02-12 14:04:53.0

Updated: 2018-05-22 08:50:12.0

Pushed: 2018-05-22 08:50:13.0

Homepage:

Size: 264

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Event Gateway JavaScript SDK

JavaScript library for interacting with the Event Gateway.

Build Status

Contents
Installation

Node:

install @serverless/event-gateway-sdk

Browser:

ipt type="text/javascript" src="https://unpkg.com/@serverless/event-gateway-sdk@latest/dist/event-gateway-sdk.min.js"></script>

The EventGateway SDK will then be attached to window e.g. and you can access it via window.EventGatewaySDK

Application Usage

When using in your application logic, you'll usually interact with the invoke and emit APIs.

Use the invoke command to synchronously invoke backend function by name. This is similar to an RPC call.

onstruct your client
t SDK = require('@serverless/event-gateway-sdk');
t eventGateway = new SDK({
l: 'http://myeventgateway.io',
ace: 'prod'


all your function
tGateway.invoke({
nctionId: 'users.getUsers',
ta: { 'limit': 100 }
hen((resp) => resp.json())
hen((users) => console.log(users))

Use the emit command to emit a named event and payload to your Event Gateway. The event will be received by any function that is subscribed to your event.

onstruct your client
t SDK = require('@serverless/event-gateway-sdk');
t eventGateway = new SDK({
l: 'http://myeventgateway.io',
ace: 'prod'


mit your event
tGateway.emit({
ent: 'user.completedTutorial'
ta: { 'userId': 1234 }

API Reference
Constructor

Parameters

Object:

t SDK = require('@serverless/event-gateway-sdk');
t eventGateway = new SDK({
l: 'http://localhost',
ace: 'mycompany-prod',
cessKey: '1234abcd'

Configuration APIs
List Functions

Returns

Promise object resolving to array of function objects

tGateway.listFunctions()
Register Function

Parameters

Object:

For more details see Event Gateway Register Functions docs.

Returns

Promise object resolving to Function object

tGateway.registerFunction({
nctionId: 'sendEmail',
pe:'awslambda',
ovider: {
arn: 'xxx',
region: 'us-west-2',


Update Function

Parameters

Object:

For more details see Event Gateway Update Functions docs.

Returns

Promise object resolving to Function object

tGateway.updateFunction({
nctionId: 'sendEmail',
pe:'awslambda',
ovider: {
arn: 'xxx',
region: 'us-west-2',


Delete Function

Parameters

Object:

tGateway.deleteFunction({ functionId: 'sendEmail' })
List Subscriptions

Returns

Promise object resolving to array of subscription objects

tGateway.listSubscriptions()
Subscribe

Parameters

Object:

For more details see Event Gateway Create Subscription docs.

Returns

Promise object resolving to Subscription object

tGateway.subscribe({
ent: 'user.created',
nctionId: 'sendEmail'

Unsubscribe

Parameters

Object:

tGateway.unsubscribe({
bscriptionId: 'user.created-sendEmail'

Events API
Emit

Parameters

Object:

Returns

fetch response object.

tGateway.emit({
ent: 'user.completedTutorial'
ta: { 'userId': 1234 }

Invoke

Parameters

Object:

Returns

fetch response object.

tGateway.invoke({
nctionId: 'users.getUsers'
ta: { 'limit': 100 }
hen((resp) => resp.json())
hen((users) => console.log(users))
Contribute

If you are interested to contribute we recommend to check out the Contributing document as it explains how to get started and some of the design decisions for this library.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.