Crate axum_bindform

Source
Expand description

Bind XML, JSON, URL-encoded or query-string form data in Axum.

§Example

use axum::http::StatusCode;
use axum_bindform::{BindForm, TryBindForm};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct Human {
    name: String,
    age: u8,
}

async fn greet_human(BindForm(form): BindForm<Human>) -> String {
    format!("Hello {} year old named {}!", form.age, form.name)
}

async fn try_greet_human(
    TryBindForm(form): TryBindForm<Human>,
) -> Result<String, (StatusCode, String)> {
    let form = form.map_err(|e| {
        (
            StatusCode::BAD_REQUEST,
            format!("Error parsing form: {}", e),
        )
    })?;
    Ok(format!("Hello {} year old named {}!", form.age, form.name))
}

Structs§

BindForm
Bind form data in Axum, rejects on error.
BindFormRejection
Rejection for BindForm.
TryBindForm
Try to bind form data in Axum and return the result, does not reject.

Enums§

BindError
Errors that can occur when binding.

Type Aliases§

BindResult
Result of binding.