For the complete documentation index, see llms-docs.txt or the site index llms.txt. Full docs corpus: llms-full-docs.txt. Prefer the markdown version of this page at /docs/examples/rust/axum.md. Product capabilities: skill.md. Docs MCP: /docs/mcp. Site MCP: /mcp.

Axum

Learn how to integrate Reloop with Axum.

Axum Integration

Integrate Reloop into your Rust application using the Axum web framework.

Installation

Add the official Rust SDK and standard tokio dependencies to your Cargo.toml:

[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
reloop = "0.1"
serde_json = "1"

Sending an Email

use axum::{routing::post, Json, Router};
use reloop::ReloopClient;
use serde_json::json;
use std::env;

#[tokio::main]
async fn main() {
    let app = Router::new().route("/send-email", post(send_email));
    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

async fn send_email() -> Result<Json<serde_json::Value>, (axum::http::StatusCode, String)> {
    let api_key = env::var("RELOOP_API_KEY").map_err(|_| {
        (axum::http::StatusCode::INTERNAL_SERVER_ERROR, "Missing API Key".to_string())
    })?;

    let client = ReloopClient::new(api_key, None);

    match client.mail().send(json!({
        "from": "onboarding@reloop.sh",
        "to": "delivered@resend.dev",
        "subject": "Hello from Axum",
        "html": "<p>Congrats on sending your first email via Reloop from Rust Axum!</p>",
    })).await {
        Ok(res) => Ok(Json(res)),
        Err(e) => Err((axum::http::StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
    }
}

Was this page helpful?

Edit this page