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
- Bind form data in Axum, rejects on error.
- Rejection for
BindForm
. - Try to bind form data in Axum and return the result, does not reject.
Enums
- Errors that can occur when binding.
Type Definitions
- Result of binding.