GithubHelp home page GithubHelp logo

resend-rust's Introduction

resend-rs

Build Status Crate Docs Crate Version

A minimal Resend client.

Add with:

cargo add resend-rs
cargo add tokio -F macros,rt-multi-thread

Emails are sent via the Resend client which provides both a synchronous and asynchronous send method. The two are mutually exclusive and accessible via the blocking feature. The crate uses reqwest and serde internally.

Documentation

Crate documentation is available in docsrs. Example usage is available in the get started guide on the Resend website, you can also find examples in the API reference.

Features

  • blocking to enable the blocking client.
  • native-tls to use system-native TLS. Enabled by default.
  • rustls-tls to use TLS backed by rustls.

Variables

  • RESEND_API_KEY to enable impl Default for a Resend client (Required).
  • RESEND_BASE_URL to override the default base address: https://api.resend.com (Optional).
  • RESEND_RATE_LIMIT to set the maximum amount of requests you can send per second. By default, this is 9 (Resend defaults to 10). See the docs for more information.
WARNING: Rate limiting only works when using the async version (default) of the crate

resend-rust's People

Contributors

antoniosbarotsis avatar martsokha avatar zenorocha avatar

Stargazers

Ayodeji O. avatar  avatar Gabriel Silva (Gabe) avatar Arran France avatar Masanori Tani avatar Ankesh Bharti avatar Francis Boulet-Rouleau avatar Shina avatar Marcos Lima avatar Jerry Wu avatar Eduardo Stuart avatar Xtian avatar Gennaro Landolfi avatar DeAndre Johnson avatar Daniel Röhers Moura avatar Sandalots avatar Shun Kakinoki avatar  avatar Kewyn Akshlley avatar Gabriel Miranda avatar anand jain avatar Rodrigo Santos de Souza avatar Mike Teddy Omondi avatar Tarek H Ghosn avatar Romain Baumier avatar  avatar  avatar Mutalisk avatar  avatar Micha Hernandez van Leuffen avatar

Watchers

Kewyn Akshlley avatar  avatar

Forkers

zssssssf

resend-rust's Issues

Ability to print JSON payload in the event of an error

This should be mostly useful for internal use (or for when submitting a bug report for the crate). The users of the crate shouldn't have to interact directly with the raw JSON ever since it is fully parsed into structs.

This won't add a new dependency since serde_json is already used by reqwest.

This is a low priority issue so I'll do this eventually™.

Checklist

  • replace all the response.json::<SomeStruct>().await?; calls to a response.text().await? and serde_json::from_str::<SomeStruct>(...) calls
  • Make sure to redact any sensitive information before saving to the error struct
  • Maybe feature gate (or debug build gate?) this entire thing to not move giant strings around all the time

Standardization - tracking issue

List of things that need to be done to bring this crate up to spec with resend-node.

Lib

  • Rename everything to match resend-node
  • Restructure the modules to follow resend-node (for example the batch module)
  • User agent should not be editable by users
  • cross check if optionals are used correctly (between resend-node and API docs)
  • Fix the email.retrieve null bug (see example return)
  • Handle rate limits

Other

  • Improve/update docs in the docs.rs homepage (also mention any other needed dependencies such as tokio)
  • Update changelog
  • Change license to MIT (oops)
  • Check for breaking changes in CI
  • Make sure no links are pointing to the old repo url
  • Fix outdated links in rustdoc comments
  • Update the README (link to the official docs when those are merged)

"invalid type: null, expected a string" when fetching an email

Hello,
Thanks for the library!

I've encountered the following error when fetching an email using client.emails.get():

thread 'main' panicked at src/main.rs:11:10:
called `Result::unwrap()` on an `Err` value: Http(reqwest::Error { kind: Decode, source: Error("invalid type: null, expected a sequence", line: 1, column: 285) })

The error comes from trying to deserialize the email into the Email struct:

  • bcc can be null, yet a Vec is expected
  • cc can be null, yet a Vec is expected
  • text can be null, yet a String is expected

Here is a minimal reproductive example:

[package]
name = "repro"
version = "0.1.0"
authors = [""]
edition = "2021"

[dependencies]
resend-rs = "0.8.0"
serde = "1.0.204"
serde_json = "1.0.120"
serde_path_to_error = "0.1.16"
tokio = { version = "1", features = ["full"] }
use resend_rs::types::Email;

#[tokio::main]
async fn main() {
    let email = r#"{
        "object": "email",
        "id": "6757a66c-3a5b-49ee-98cc-fca7a5f423c0",
        "to": [
            "[email protected]"
        ],
        "from": "[email protected]>",
        "created_at": "2024-07-11 07:49:53.682607+00",
        "subject": "Subject",
        "bcc": null,
        "cc": null,
        "reply_to": null,
        "last_event": "delivered",
        "html": "<div></div>",
        "text": null
    }"#;

    let jd = &mut serde_json::Deserializer::from_str(email);
    let result: Result<Email, _> = serde_path_to_error::deserialize(jd);
    result.unwrap();
}

Running the code gives us the following error:

thread 'main' panicked at src/main.rs:24:12:
called `Result::unwrap()` on an `Err` value: Error { path: Path { segments: [Map { key: "bcc" }] }, original: Error("invalid type: null, expected a sequence", line: 10, column: 19) }

Make all input struct fields private

The idea behind this is that whenever new fields need to be added to the input structs, it would be a minor instead of a major change like in #14.

Blocked by #14, will include both that and this issue in the same major release.

Checklist

  • Make sure none of the official docs directly instantiate structs and if they do, change them
  • CreateApiKeyOptions
  • CreateEmailBaseOptions
  • ContactData
  • ContactChanges
  • CreateDomainOptions
  • DomainChanges
  • UpdateEmailOptions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.