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
Size: 264
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
JavaScript library for interacting with the Event Gateway.
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
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 }
Parameters
Object:
url
- string
- required, Events API URLconfigurationUrl
- string
- optional, Configuration API URL. By default, it's the same as url
but with 4001
portspace
- string
- optional, space name, default: default
accessKey
- string
- optional, access key for hosted Event Gateway. Access key is required for using Configuration API methods on hosted Event GatewayfetchClient
- object
- optional, fetch
clientt SDK = require('@serverless/event-gateway-sdk');
t eventGateway = new SDK({
l: 'http://localhost',
ace: 'mycompany-prod',
cessKey: '1234abcd'
Returns
Promise object resolving to array of function objects
tGateway.listFunctions()
Parameters
Object:
functionId
- string
- function IDtype
- string
- type of function providerprovider
- object
- provider specFor 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',
Parameters
Object:
functionId
- string
- function IDtype
- string
- type of function providerprovider
- object
- provider specFor 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',
Parameters
Object:
functionId
- string
- function IDtGateway.deleteFunction({ functionId: 'sendEmail' })
Returns
Promise object resolving to array of subscription objects
tGateway.listSubscriptions()
Parameters
Object:
event
- string
- event typefunctionId
- string
- function IDpath
- string
- optional, subscription path, default: /
method
- string
- required for HTTP subscription, HTTP methodcors
- object
- optional for HTTP subscriptions, CORS configurationFor more details see Event Gateway Create Subscription docs.
Returns
Promise object resolving to Subscription object
tGateway.subscribe({
ent: 'user.created',
nctionId: 'sendEmail'
Parameters
Object:
subscriptionId
- string
- subscription IDtGateway.unsubscribe({
bscriptionId: 'user.created-sendEmail'
Parameters
Object:
event
- string
- Name of event to emitdata
- object
or string
- Payload to include with event. If dataType
is "application/json"
, data will be stringified before sending.dataType
- string
- Data type of payload. Default is "application/json"
Returns
fetch
response object.
tGateway.emit({
ent: 'user.completedTutorial'
ta: { 'userId': 1234 }
Parameters
Object:
functionId
- string
- Name of function to invokedata
- object
or string
- Payload to include with invocation. If dataType
is "application/json"
, data will be stringified before sending.dataType
- string
- Data type of payload. Default is "application/json"
Returns
fetch
response object.
tGateway.invoke({
nctionId: 'users.getUsers'
ta: { 'limit': 100 }
hen((resp) => resp.json())
hen((users) => console.log(users))
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.