{"id":19042453,"url":"https://github.com/serverless/event-gateway-sdk","last_synced_at":"2025-04-23T22:28:00.098Z","repository":{"id":57140118,"uuid":"121253784","full_name":"serverless/event-gateway-sdk","owner":"serverless","description":"Event Gateway JavaScript SDK","archived":false,"fork":false,"pushed_at":"2018-12-13T10:22:00.000Z","size":396,"stargazers_count":44,"open_issues_count":7,"forks_count":11,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-11-03T05:23:41.674Z","etag":null,"topics":["event-gateway","faas","sdk-js","sdk-nodejs","serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serverless.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-12T14:04:53.000Z","updated_at":"2024-07-11T01:55:06.000Z","dependencies_parsed_at":"2022-09-04T22:10:25.509Z","dependency_job_id":null,"html_url":"https://github.com/serverless/event-gateway-sdk","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless%2Fevent-gateway-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless%2Fevent-gateway-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless%2Fevent-gateway-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless%2Fevent-gateway-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serverless","download_url":"https://codeload.github.com/serverless/event-gateway-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223764358,"owners_count":17198609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["event-gateway","faas","sdk-js","sdk-nodejs","serverless"],"created_at":"2024-11-08T22:37:42.666Z","updated_at":"2024-11-08T22:37:43.205Z","avatar_url":"https://github.com/serverless.png","language":"JavaScript","readme":"# Event Gateway JavaScript SDK\n\nJavascript library for interacting with the [Event Gateway](https://github.com/serverless/event-gateway).\n\n[![Build Status](https://travis-ci.org/serverless/event-gateway-sdk.svg?branch=master)](https://travis-ci.org/serverless/event-gateway-sdk)\n[![Known Vulnerabilities](https://snyk.io/test/github/serverless/event-gateway-sdk/badge.svg)](https://snyk.io/test/github/serverless/event-gateway-sdk)\n\n## Contents\n\n- [Background](#background)\n- [Target Audience](#target-audience)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Constructor](#constructor)\n- [API Reference](#api-reference)\n- [Contributing](#contributing)\n\n## Background\n\nThis is the Javascript SDK for interacting with the [Event Gateway](https://github.com/serverless/event-gateway), the hub for connecting events to serverless functions. It is designed to work both on the server with Node.js and in the browser.\n\n## Target Audience\n\nThis SDK can be used both to *configure* the Event Gateway, by registering functions and subscriptions, and to *interact* with the Event Gateway, by emitting events from your application to be sent to subscribed functions.\n\nThis README is focused on the latter use case -- interacting with the Event Gateway by emitting events. If you're interested in using the Event Gateway SDK to configure the Event Gateway, please check the [API reference](./docs/api.md) for the available methods, as well as the main [Event Gateway repository](https://github.com/serverless/event-gateway). You may also be interested in using the [Event Gateway plugin](https://github.com/serverless/serverless-event-gateway-plugin) for the [Serverless Framework](https://github.com/serverless/serverless) to configure the Event Gateway.\n\n## Installation\n\nNode:\n\n```bash\nnpm install @serverless/event-gateway-sdk\n```\n\nBrowser:\n\n```html\n\u003cscript type=\"text/javascript\" src=\"https://unpkg.com/@serverless/event-gateway-sdk@latest/dist/event-gateway-sdk.min.js\"\u003e\u003c/script\u003e\n```\n\nThe EventGateway SDK will then be attached to window e.g. and you can access it via `window.EventGatewaySDK`\n\n## Usage\n\nUse the `emit` command to emit a [CloudEvent](https://github.com/cloudevents/spec) payload to your Event Gateway. The event will be received by any function that is subscribed to your event.\n\n```javascript\n// Construct your client\nconst SDK = require('@serverless/event-gateway-sdk');\nconst eventGateway = new SDK({\n  url: 'https://mytenant-myapp.slsgateway.com',\n})\n\n// Emit your event\neventGateway\n  .emit({\n    eventID: '1',\n    eventType: 'user.created',\n    cloudEventsVersion: '0.1',\n    source: '/services/users',\n    contentType: 'application/json',\n    data: {\n      userID: 'foo'\n    }\n  }, {\n    path: '/users',\n    headers: {\n      \"Authorization\": \"Bearer 124567890\"\n    }\n  })\n  // If a sync subscription, then do something with the response.\n  .then(res =\u003e res.json())\n  .then(json =\u003e console.log(json))\n```\n\nThe `emit()` function takes two arguments: an `event` which is a valid CloudEvent, plus an optional `options` object to include a path and/or headers to pass with your event.\n\nThe function returns a [`fetch`](https://github.com/bitinn/node-fetch) response object. If your event has a `sync` subscription attached, the `fetch` response will have the status code and body from the subscription. If not, the response will return a `202 Accepted` status code with an empty body.\n\n## Constructor\n\nIn the example above, we created an Event Gateway client using the application URL from the [hosted Event Gateway](https://dashboard.serverless.com/) provided by Serverless, Inc. \n\nYou can also use the Event Gateway SDK with your own, self-hosted Event Gateway. Constructor details are listed below.\n\n**Parameters**\n\nObject:\n\n- `url` - `string` - required, Events API URL\n- `configurationUrl` - `string` -  optional, Configuration API URL. By default, it's the same as `url` but with `4001` port\n- `space` - `string` - optional, space name, default: `default`\n- `accessKey` - `string` - optional, access key for hosted Event Gateway. Access key is required for using Configuration API methods on hosted Event Gateway\n- `fetchClient` - `object` - optional, `fetch` client\n\n**Example**\n\n```js\nconst SDK = require('@serverless/event-gateway-sdk');\nconst eventGateway = new SDK({\n  url: 'http://localhost',\n  space: 'mycompany-prod',\n  accessKey: '1234abcd'\n})\n```\n\n## API Reference\n\nFor all available methods in the Event Gateway SDK, please see the [API reference](./docs/api.md).\n\n## Contribute\n\nIf you are interested to contribute we recommend to check out the [Contributing](https://github.com/serverless/event-gateway-sdk/blob/master/CONTRIBUTING.md) document as it explains how to get started and some of the design decisions for this library.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless%2Fevent-gateway-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserverless%2Fevent-gateway-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless%2Fevent-gateway-sdk/lists"}