Skip to content

Starts an HTTP server that streams events as NDJSON to connected clients.

serve_http url:string, [path=string, method=string, responses=record,
max_connections=int, tls=record]

The serve_http operator starts an HTTP server and streams pipeline events as NDJSON to any HTTP client that connects. Each connected client receives a copy of every event.

The operator waits for at least one client to connect before delivering data. When the pipeline finishes, the server shuts down and all client connections are closed.

Clients that connect to a path other than the stream path, or use the wrong HTTP method, receive a 404 or 405 response respectively. Use the responses option to serve static content on additional paths, such as health checks.

The endpoint to listen on. Must have the form <host>:<port>. Use 0.0.0.0 to accept connections on all interfaces.

The URL path that clients connect to for the event stream.

Defaults to "/".

The HTTP method that clients must use to connect to the stream.

Defaults to "GET".

Serve fixed responses on auxiliary paths that are separate from the event stream. This is useful for health checks or status endpoints. For example:

responses={
"/health": {code: 200, content_type: "text/plain", body: "ok"},
}

Clients hitting /health receive the static body defined here, while clients connecting to the stream path receive the live NDJSON event stream from the pipeline.

Each route must be a record with code, content_type, and body fields. The stream path itself cannot appear in responses.

The maximum number of simultaneous client connections to accept.

Defaults to 128.

TLS configuration. Provide an empty record (tls={}) to enable TLS with defaults or set fields to customize it.

{
skip_peer_verification: bool, // skip certificate verification.
cacert: string, // CA bundle to verify peers.
certfile: string, // client certificate to present.
keyfile: string, // private key for the client certificate.
min_version: string, // minimum TLS version (`"1.0"`, `"1.1"`, `"1.2"`, "1.3"`).
ciphers: string, // OpenSSL cipher list string.
client_ca: string, // CA to validate client certificates.
require_client_cert, // require clients to present a certificate.
}

The client_ca and require_client_cert options are only applied for operators that accept incoming client connections, and otherwise ignored.

Any value not specified in the record will either be picked up from the configuration or if not configured will not be used by the operator.

See the Node TLS Setup guide for more details.

Serve events on port 8080. Any HTTP client connecting to http://host:8080/ receives the events as NDJSON:

export
serve_http "0.0.0.0:8080"

Connect with curl:

Terminal window
curl http://localhost:8080/

Require clients to POST to /events:

export
serve_http "0.0.0.0:8080", path="/events", method="post"

Expose a health endpoint alongside the event stream:

export
serve_http "0.0.0.0:8080",
responses={
"/health": {code: 200, content_type: "text/plain", body: "ok"},
}
export
serve_http "0.0.0.0:8443",
tls={
certfile: "/path/to/cert.pem",
keyfile: "/path/to/key.pem",
}

Last updated: