---
title: Axum
description: Learn how to integrate Reloop with Axum.
icon: siRust
---
> For the complete documentation index, see [llms-docs.txt](/llms-docs.txt) or the site index [llms.txt](/llms.txt). Full docs corpus: [llms-full-docs.txt](/llms-full-docs.txt). Prefer markdown URLs (append `.md`) for agent consumption. Product skill: [skill.md](/skill.md).


# 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`:

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

## Sending an Email

```rust
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())),
    }
}
```
