HTTPEmitter

HTTPEmitter

const { SPEC_V03, SPEC_V1 } = require("./constants");

/** A class which is capable of sending binary and structured events using the CloudEvents HTTP Protocol Binding specification.

Constructor

new HTTPEmitter(optionsopt)

Creates a new instance of {HTTPEmitter}. The default emitter uses the 1.0 protocol specification in binary mode.

Parameters:
Name Type Attributes Description
options Object <optional>

The configuration options for this event emitter

Properties
Name Type Attributes Description
url URL

The endpoint that will receive the sent events.

version string <optional>

The HTTP binding specification version. Default: "1.0"

Source:
See:
Throws:

if no options.url is provided or an unknown specification version is provided.

Type
TypeError

Methods

headers(event) → {Object}

Returns the HTTP headers that will be sent for this event when the HTTP transmission mode is "binary". Events sent over HTTP in structured mode only have a single CE header and that is "ce-id", corresponding to the event ID.

Parameters:
Name Type Description
event CloudEvent

a CloudEvent

Source:

send(event, optionsopt) → {Promise}

Sends the {CloudEvent} to an event receiver over HTTP POST

Parameters:
Name Type Attributes Description
event CloudEvent

the CloudEvent to be sent

options Object <optional>

The configuration options for this event. Options provided will be passed along to Node.js http.request(). https://nodejs.org/api/http.html#http_http_request_options_callback

Properties
Name Type Attributes Description
url URL <optional>

The HTTP/S url that should receive this event. The URL is optional if one was provided when this emitter was constructed. In that case, it will be used as the recipient endpoint. The endpoint can be overridden by providing a URL here.

mode string <optional>

the message mode for sending this event. Possible values are "binary" and "structured". Default: structured

Source: