cloudevents/binding/poem/mod.rs
1//! This module integrates the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) with
2//! [Poem](https://docs.rs/poem/) to easily send and receive CloudEvents.
3//!
4//! To deserialize an HTTP request as CloudEvent
5//!
6//! To echo events:
7//!
8//! ```rust
9//! use cloudevents::Event;
10//! use poem_lib as poem;
11//! use poem::{handler, Route, post};
12//!
13//! #[handler]
14//! async fn index(event: Event) -> Event {
15//! println!("received cloudevent {}", &event);
16//! event
17//! }
18//!
19//! let app = Route::new().at("/", post(index));
20//! ```
21//!
22//! To create event inside request handlers and send them as responses:
23//!
24//! ```rust
25//! use cloudevents::{Event, EventBuilder, EventBuilderV10};
26//! use poem_lib as poem;
27//! use poem::{handler, Route, post, Result};
28//! use poem::error::InternalServerError;
29//! use serde_json::json;
30//!
31//! #[handler]
32//! async fn index() -> Result<Event> {
33//! let event = EventBuilderV10::new()
34//! .id("1")
35//! .source("url://example_response/")
36//! .ty("example.ce")
37//! .data(
38//! mime::APPLICATION_JSON.to_string(),
39//! json!({
40//! "name": "John Doe",
41//! "age": 43,
42//! "phones": [
43//! "+44 1234567",
44//! "+44 2345678"
45//! ]
46//! }),
47//! )
48//! .build()
49//! .map_err(InternalServerError)?;
50//! Ok(event)
51//! }
52//!
53//! let app = Route::new().at("/", post(index));
54//! ```
55
56mod extractor;
57mod response;