pastjean / postmark-rs

Postmark client for rust
https://docs.rs/postmark
Apache License 2.0
10 stars 9 forks source link

Unable to complete queries due to hyper error #19

Closed kingledion closed 1 year ago

kingledion commented 1 year ago

I'm opening this issue because I ran into some trouble with manual testing. When I went to test my template changes against the API, using the skipped test, I have been hitting snags with sending any sort of request to the Postmark API.

The manual test in this branch can be run with cargo test --test send_email. I made the test match what is in the package docstrings pretty closely.

The error I am getting back from the .execute() call is:

thread 'send_email' panicked at 'called `Result::unwrap()` on an `Err` value: Client { source: Communication { source: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.postmarkapp.com")), port: None, path: "/email", query: None, fragment: None }, source: hyper::Error(Connect, "invalid URL, scheme is not http") } } }', tests/send_email.rs:37:10

The error message invalid URL, scheme is not http can be traced to here: https://docs.rs/hyper/latest/src/hyper/client/connect/http.rs.html#285

This error will throw when the scheme is https. I'm not sure what is going on in the middle with reqwest and why it is expecting http, but it should pretty clearly be https to communicate with Postmark.

pastjean commented 1 year ago

Um.. I feel this is due to a required feature in hyper, I'll look into this when I got time.

kingledion commented 1 year ago

The fundamental problem for me is that I have done all this work and can't get an example working! Do you have any working example code that I can check out?

pastjean commented 1 year ago

The example you have written works when you have either tls feature enabled

reqwest-native-tls = ["reqwest", "reqwest/native-tls"]
reqwest-rustls-tls = ["reqwest", "reqwest/rustls-tls"]
    println!("Started test");

    let api_token = "mytoken";

    println!("Loaded env variable");

    let client = PostmarkClient::builder().token(api_token).build();

    println!("Created client");

    let req = CreateTemplateRequest::builder()
        .name("Hello")
        .body(Body::html("This is a basic e-mail test!".into()))
        .build();

    println!("Created Template \"Hello\"");

    let resp = req.execute(&client).await;
    resp.unwrap();
pastjean commented 1 year ago

I've added it to the test dependencies https://github.com/pastjean/postmark-rs/commit/641660a965144476d8da220dddfc1021f47a3344

kingledion commented 1 year ago

This solved my issue, thank you for pointing this out to me.