resend_rust/
batch.rs

1use crate::{emails, http, parse_response, utils, Client, Error};
2
3#[derive(serde_derive::Deserialize)]
4pub struct BatchSendResponse {
5    pub data: Vec<emails::SendEmailResponse>,
6}
7
8pub async fn send(
9    client: &Client,
10    r: &[emails::SendEmailRequest],
11) -> Result<BatchSendResponse, Error> {
12    let request_json = serde_json::to_string(r).map_err(Error::JSON)?;
13
14    let url = utils::url::emails::batch(&client.base_url);
15    let request = http::Request::new(http::Method::Post, &url, Some(request_json.to_string()));
16
17    let response = parse_response(client.perform(request).await.map_err(Error::Client)?).await?;
18    serde_json::from_str(&response).map_err(Error::JSON)
19}