Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send/emit cloud events #210

Open
oasisk opened this issue Jun 1, 2023 · 3 comments
Open

How to send/emit cloud events #210

oasisk opened this issue Jun 1, 2023 · 3 comments

Comments

@oasisk
Copy link

oasisk commented Jun 1, 2023

Javascript sdk supports sending events , how to send events using rust sdk.

https://github.com/cloudevents/sdk-javascript#emitting-events

@Lazzaretti
Copy link
Member

Hi @oasisk

The SDK supports sending events. Is your question how to send an event to an HTTP endpoint? Are you looking for a browser-based solution (so with a WebAssembly)?
And how should the event be encoded (e.g. JSON)?

@oasisk
Copy link
Author

oasisk commented Jun 5, 2023

@Lazzaretti ..yes..want to understand how do we send events to http end point?

@ozabalaferrera
Copy link
Contributor

ozabalaferrera commented Nov 10, 2024

This thread is very old, and I presume moot, but here is a simple example:
maybe we could close this issue?

// [dependencies]
// cloudevents-sdk = {version = "0.7", features = ["reqwest"]}
// reqwest = "0.11"
// tokio = {version = "1.41", features = ["rt-multi-thread", "macros"]}

use cloudevents::{binding::reqwest::RequestBuilderExt, Data, EventBuilder, EventBuilderV10};

#[tokio::main]
async fn main() {
    let ce = EventBuilderV10::new()
        .id("id-1")
        .source("source")
        .ty("type")
        .data("text/plain", Data::String("data".to_owned()))
        .build()
        .unwrap();

    let url = "https://httpbin.org/post";
    reqwest::Client::new()
        .post(url)
        .event(ce)
        .unwrap()
        .send()
        .await
        .unwrap();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants