Expand description
This crate integrates the cloudevents-sdk with reqwest to easily send and receive CloudEvents.
use cloudevents_sdk_reqwest::{RequestBuilderExt, ResponseExt};
use cloudevents::{EventBuilderV10, EventBuilder};
use serde_json::json;
let client = reqwest::Client::new();
// Prepare the event to send
let event_to_send = EventBuilderV10::new()
.id("0001")
.ty("example.test")
.source("http://localhost/")
.data("application/json", json!({"hello": "world"}))
.build()?;
// Send request
let response = client.post("http://localhost")
.event(event_to_send)?
.send().await?;
// Parse response as event
let received_event = response
.into_event().await?;Check out the cloudevents-sdk docs for more details on how to use cloudevents::Event.
Structs§
- Request
Serializer - Wrapper for
RequestBuilderthat implementsStructuredSerializer&BinarySerializertraits. - Response
Deserializer - Wrapper for
Responsethat implementsMessageDeserializertrait.
Traits§
- Request
Builder Ext - Extension Trait for
RequestBuilderwhich acts as a wrapper for the functionevent_to_request(). - Response
Ext - Extension Trait for
Responsewhich acts as a wrapper for the functionresponse_to_event().
Functions§
- event_
to_ request - Method to fill a
RequestBuilderwith anEvent. - response_
to_ event - Method to transform an incoming
ResponsetoEvent.