All Projects → cloudevents → Sdk Javascript

cloudevents / Sdk Javascript

Licence: apache-2.0
Javascript SDK for CloudEvents

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Sdk Javascript

Eventrouter
A simple introspective kubernetes service that forwards events to a specified sink.
Stars: ✭ 671 (+408.33%)
Mutual labels:  events, cncf
sdk-python
Python SDK for CloudEvents
Stars: ✭ 149 (+12.88%)
Mutual labels:  events, cncf
Action
Easy and lazy solution for click-event-binding.
Stars: ✭ 92 (-30.3%)
Mutual labels:  events
Backstage
Backstage is an open platform for building developer portals
Stars: ✭ 14,296 (+10730.3%)
Mutual labels:  cncf
Fluentd
Fluentd: Unified Logging Layer (project under CNCF)
Stars: ✭ 10,807 (+8087.12%)
Mutual labels:  cncf
Telemetry poller
Periodically gather measurements and publish them as Telemetry events
Stars: ✭ 101 (-23.48%)
Mutual labels:  events
Call For Papers
List with open Call for Papers
Stars: ✭ 118 (-10.61%)
Mutual labels:  events
Falco Security Workshop
Container Security Workshop covering using Falco on Kubernetes.
Stars: ✭ 91 (-31.06%)
Mutual labels:  cncf
Gatekeeper
Gatekeeper - Policy Controller for Kubernetes
Stars: ✭ 2,194 (+1562.12%)
Mutual labels:  cncf
Lifecycle
Reference implementation of the Cloud Native Buildpacks lifecycle
Stars: ✭ 109 (-17.42%)
Mutual labels:  cncf
Litmus
Litmus helps SREs and developers practice chaos engineering in a Cloud-native way. Chaos experiments are published at the ChaosHub (https://hub.litmuschaos.io). Community notes is at https://hackmd.io/a4Zu_sH4TZGeih-xCimi3Q
Stars: ✭ 2,377 (+1700.76%)
Mutual labels:  cncf
Truffle Assertions
🛠 Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
Stars: ✭ 109 (-17.42%)
Mutual labels:  events
Event Espresso Core
Event Espresso 4 Core for WordPress: Build an Event Ticketing Website Today!
Stars: ✭ 107 (-18.94%)
Mutual labels:  events
Joynr
A transport protocol agnostic (MQTT, HTTP, WebSockets etc.) Franca IDL based communication framework supporting multiple communication paradigms (RPC, Pub-Sub, broadcast etc.)
Stars: ✭ 124 (-6.06%)
Mutual labels:  events
Kubernetes Oom Event Generator
Generate a Kubernetes Event when a Pod's container has been OOMKilled
Stars: ✭ 93 (-29.55%)
Mutual labels:  events
Sig App Delivery
📨🚚CNCF App Delivery SIG
Stars: ✭ 124 (-6.06%)
Mutual labels:  cncf
Tikv
Distributed transactional key-value database, originally created to complement TiDB
Stars: ✭ 10,403 (+7781.06%)
Mutual labels:  cncf
Samples
Community driven repository for Dapr samples
Stars: ✭ 104 (-21.21%)
Mutual labels:  events
Unityanimatorevents
UnityEvents triggered by states inside an Animator. Easy to use and performant.
Stars: ✭ 117 (-11.36%)
Mutual labels:  events
Image Promise
🎑🤞 Load one or more images, return a promise. Tiny, browser-only, no dependencies.
Stars: ✭ 129 (-2.27%)
Mutual labels:  events

JavaScript SDK for CloudEvents

Codacy Badge Codacy Badge Node.js CI npm version vulnerabilities

The CloudEvents SDK for JavaScript.

Features

  • Represent CloudEvents in memory
  • Serialize and deserialize CloudEvents in different event formats.
  • Send and recieve CloudEvents with via different protocol bindings.

Note: Supports CloudEvent versions 0.3, 1.0

Installation

The CloudEvents SDK requires a current LTS version of Node.js. At the moment those are Node.js 10.x and Node.js 12.x. To install in your Node.js project:

npm install cloudevents

Receiving and Emitting Events

Receiving Events

You can choose any popular web framework for port binding. A CloudEvent object can be created by simply providing the HTTP protocol binding the incoming headers and request body.

const app = require("express")();
const { HTTP } = require("cloudevents");

app.post("/", (req, res) => {
  // body and headers come from an incoming HTTP request, e.g. express.js
  const receivedEvent = HTTP.toEvent({ headers: req.headers, body: req.body });
  console.log(receivedEvent);
});

Emitting Events

You can send events over HTTP in either binary or structured format using the HTTP binding to create a Message which has properties for headers and body.

const axios = require("axios").default;
const { HTTP, CloudEvent } = require("cloudevents");

const ce = new CloudEvent({ type, source, data });
const message = HTTP.binary(ce); // Or HTTP.structured(ce)

axios({
  method: "post",
  url: "...",
  data: message.body,
  headers: message.headers,
});

You may also use the emitterFor() function as a convenience.

const axios = require("axios").default;
const { emitterFor, Mode, CloudEvent } = require("cloudevents");

function sendWithAxios(message) {
  // Do what you need with the message headers
  // and body in this function, then send the
  // event
  axios({
    method: "post",
    url: "...",
    data: message.body,
    headers: message.headers,
  });
}

const emit = emitterFor(sendWithAxios, { mode: Mode.BINARY });
emit(new CloudEvent({ type, source, data }));

You may also use the Emitter singleton

const axios = require("axios").default;
const { emitterFor, Mode, CloudEvent, Emitter } = require("cloudevents");

function sendWithAxios(message) {
  // Do what you need with the message headers
  // and body in this function, then send the
  // event
  axios({
    method: "post",
    url: "...",
    data: message.body,
    headers: message.headers,
  });
}

const emit = emitterFor(sendWithAxios, { mode: Mode.BINARY });
// Set the emit
Emitter.on("cloudevent", emit);

...
// In any part of the code will send the event
new CloudEvent({ type, source, data }).emit();

// You can also have several listener to send the event to several endpoint

CloudEvent Objects

All created CloudEvent objects are read-only. If you need to update a property or add a new extension to an existing cloud event object, you can use the cloneWith method. This will return a new CloudEvent with any update or new properties. For example:

const {
  CloudEvent,
} = require("cloudevents");

// Create a new CloudEvent
const ce = new CloudEvent({...});

// Add a new extension to an existing CloudEvent
const ce2 = ce.cloneWith({extension: "Value"});

Example Applications

There are a few trivial example applications in the examples folder. There you will find Express.js, TypeScript and Websocket examples.

API Transition Guide

Guide Link

Supported specification features

Core Specification v0.3 v1.0
CloudEvents Core ✔️ ✔️

Event Formats v0.3 v1.0
AVRO Event Format
JSON Event Format ✔️ ✔️

Transport Protocols v0.3 v1.0
AMQP Protocol Binding
HTTP Protocol Binding ✔️ ✔️
Kafka Protocol Binding
MQTT Protocol Binding
NATS Protocol Binding

Community

Contributing

We love contributions from the community! Please check the Contributor's Guide for information on how to get involved.

Each SDK may have its own unique processes, tooling and guidelines, common governance related material can be found in the CloudEvents community directory. In particular, in there you will find information concerning how SDK projects are managed, guidelines for how PR reviews and approval, and our Code of Conduct information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].