[][src]Crate cloudevents_sdk_reqwest

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

RequestSerializer

Wrapper for RequestBuilder that implements StructuredSerializer & BinarySerializer traits.

ResponseDeserializer

Wrapper for Response that implements MessageDeserializer trait.

Traits

RequestBuilderExt

Extension Trait for RequestBuilder which acts as a wrapper for the function event_to_request().

ResponseExt

Extension Trait for Response which acts as a wrapper for the function response_to_event().

Functions

event_to_request

Method to fill a RequestBuilder with an Event.

response_to_event

Method to transform an incoming Response to Event.