Name: fdk
Owner: Serverless
Description: This library is deprecated. Please use https://github.com/serverless/event-gateway-sdk instead.
Created: 2016-11-03 13:43:27.0
Updated: 2018-05-15 04:55:17.0
Pushed: 2018-02-20 10:46:05.0
Size: 34621
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
IMPORTANT: This library is deprecated. Please use https://github.com/serverless/event-gateway-sdk instead.
Node.js library to improve developer experience developing Serverless applications.
It contains a client to configure and interact with the Event Gateway.
install @serverless/fdk
ipt type="text/javascript" src="https://unpkg.com/@serverless/fdk@latest/dist/fdk.min.js"></script>
The FDK then will be attached to window e.g. and you can access it via window.fdk
t fdk = require('@serverless/fdk');
t eventGateway = fdk.eventGateway({
l: 'http://localhost',
Optional Properties for eventGateway
defaults to the provide URL + default config port 4001
nfigurationUrl: 'http://localhost:4001'
optional property to provide their own http lib
tchClient: fetch
tGateway.invoke({
nctionId: "createUser",
ta: { name: "Max" },
Returns a Promise with the response.
The value of data is converted using JSON.stringify
by default since the default dataType is application/json
. This is not happening and the value is passed as it is when the property dataType
is provided.
tGateway.invoke({
nctionId: "createUser",
ta: "Max",
taType: "text/plain",
tGateway.emit({
ent: "userCreated",
ta: { name: "Max" },
Returns a Promise and when resolved the response only indicates if the Event Gateway received the event. Responses from any subscribed functions are not part of the response.
The value of data is converted using JSON.stringify
by default since the default dataType is application/json
. This is not happening and the value is passed as it is when the property dataType
is provided.
tGateway.emit({
ent: "userCreated",
ta: "This is a string message.",
taType: "text/plain",
Configure accepts an object of function and subscription definitions. The idea of exposing one configuration function is to provide developers with convenient utility to configure an Event Gateway in one call rather then dealing with a chain of Promise based calls. Nevertheless in addition we expose a wrapper function for each low-level API call to the Event Gateway described in this section.
tGateway.configure({
list of all the functions that should be registered
nctions: [
{
functionId: "helloWorld"
provider: {
type: "awslambda"
arn: "xxx",
region: "us-west-2",
}
},
{
functionId: "sendWelcomeMail"
provider: {
type: "gcloudfunction"
name: "sendWelcomeEmail",
region: "us-west-2",
}
}
list of all the subscriptions that should be created
bscriptions: [
{
event: "http",
method: "GET",
path: "/users",
functionId: "helloWorld"
},
{
event: "user.created",
functionId: "sendEmail"
}
Returns a promise which contains all the same list of functions and subscriptions in the same structure and order as provided in the configuration argument.
tGateway.configure({ config })
hen((response) => {
console.log(response)
// {
// functions: [
// { functionId: 'xxx', ? },
// { functionId: 'xxx', ? }
// ],
// subscriptions: [
// { subscriptionId: 'xxx', ? },
// { subscriptionId: 'xxx', ? }
// ]
// }
Reset removes all the existing subscriptions and functions.
tGateway.resetConfiguration()
eturns a function
tGateway.registerFunction({
nctionId: "sendEmail"
ovider: {
type: "awslambda"
arn: "xxx",
region: "us-west-2",
eturns undefined
tGateway.deleteFunction({ functionId: "sendEmail" })
eturns an Array of functions
tGateway.listFunctions()
eturns a subscription: { subscriptionId, event, functionId}
tGateway.subscribe({
ent: "user.created",
nctionId: "sendEmail"
eturns undefined
tGateway.unsubscribe({
bscriptionId: "user.created-sendEmail"
eturns an Array of subscriptions
tGateway.listSubscriptions()
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.