Event streaming

Your integration may wish to receive real time updates from Bias for fulfilling paid orders, updating your own records of payment data, or other purposes. For this reason, the Event List resources includes a stream option that will return a long-lived stream of events.

Streamed responses consist of JSON objects, separated by newlines. They are not wrapped in the usual List object, they are plain Event objects. The server will send a space character every few seconds to ensure the connection is not ended prematurely.

Example

Listen for new customers and log their names. Every server SDK exposes the stream as a language-native iterator.

TypeScript

const stream = await sdk.events.list({
    stream: true, // Request a stream instead of a list
    filters: { type: "customer.created" },
});

for await (const event of stream) {
    const customer = event.state as Customer;
    console.log(`New customer: ${customer.name}`);
}

Python

for event in client.events.stream(filters={"type": "customer.created"}):
    customer = event.state
    print(f"New customer: {customer.name}")

The async client exposes the same method as an async for iterator. See the Python SDK.

Rust

list_stream forces stream=true and returns a Stream of events, skipping heartbeats automatically:

use futures::StreamExt;

let mut stream = client
    .events()
    .list_stream(bias::EventListParams::builder().build())?;

while let Some(event) = stream.next().await {
    let event = event?;
    println!("{:?}: {}", event.r#type, event.id);
}

See the Rust SDK.