Skip to content

application/json content type set with reqwest integration insetad of expected application/cloudevents+json #214

Open
@tizz98

Description

@tizz98

I'm using the reqwest integration for sending cloud events, but the content type seems to always be set to application/json instead of application/cloudevents+json.

Here's the request made to my pipedream request bin:

Screenshot

Cargo.toml

[package]
name = "cloudevents-reqwest-demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.75"
cloudevents-sdk = { version = "0.7.0", features = ["reqwest"] }
reqwest = "0.11.20"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
tokio = { version = "1.32.0", features = ["full"] }
uuid = { version = "1.4.1", features = ["v4"] }

main.rs

use std::collections::HashMap;

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

#[tokio::main]
async fn main() {
    let target = "https://<OMITTED>.m.pipedream.net";
    let client = reqwest::Client::new();
    let mut data = HashMap::new();
    data.insert("hello", "world");

    let event = EventBuilderV10::new()
        .id(uuid::Uuid::new_v4().to_string())
        .ty("example.test")
        .source("http://localhost/")
        .data("application/json", serde_json::to_value(data).unwrap())
        .build()
        .unwrap();

    let resp = client
        .post(target)
        .event(event)
        .unwrap()
        .send()
        .await
        .unwrap();

    println!("Response: {:?}", resp);
}

I've tried a few other things that don't seem to work:

  1. Setting .data("application/cloudevents+json")
  2. Setting a .header() for content type on the request builder
  3. Using json!() serde macro for .data

I followed this example for getting set up, but I'm not using wasm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions