1 unstable release
0.1.0 | Jul 25, 2023 |
---|
#10 in #urlencoded
10KB
140 lines
axum-bindform
Bind XML, JSON, URL-encoded or query-string form data in Axum.
lib.rs
:
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))
}
Dependencies
~6–21MB
~259K SLoC