add examples and support for typed_path
This commit is contained in:
43
src/yaml.rs
43
src/yaml.rs
@@ -1,5 +1,46 @@
|
||||
//! # Implementation of the `HasValidate` trait for the `Yaml` extractor.
|
||||
//! # Support for `Yaml<T>` from `axum-yaml`
|
||||
//!
|
||||
//! ## Feature
|
||||
//!
|
||||
//! Enable the `yaml` feature to use `Valid<Yaml<T>>`.
|
||||
//!
|
||||
//! ## Usage
|
||||
//!
|
||||
//! 1. Implement `Deserialize` and `Validate` for your data type `T`.
|
||||
//! 2. In your handler function, use `Valid<Yaml<T>>` as some parameter's type.
|
||||
|
||||
//!
|
||||
//! ## Example
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use axum::routing::post;
|
||||
//! use axum::Router;
|
||||
//! use axum_valid::Valid;
|
||||
//! use axum_yaml::Yaml;
|
||||
//! use serde::Deserialize;
|
||||
//! use validator::Validate;
|
||||
//!
|
||||
//! #[tokio::main]
|
||||
//! async fn main() -> anyhow::Result<()> {
|
||||
//! let router = Router::new().route("/yaml", post(handler));
|
||||
//! axum::Server::bind(&([0u8, 0, 0, 0], 8080).into())
|
||||
//! .serve(router.into_make_service())
|
||||
//! .await?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! async fn handler(parameter: Valid<Yaml<Parameter>>) {
|
||||
//! assert!(parameter.validate().is_ok());
|
||||
//! }
|
||||
//!
|
||||
//! #[derive(Deserialize, Validate)]
|
||||
//! struct Parameter {
|
||||
//! #[validate(range(min = 5, max = 10))]
|
||||
//! v0: i32,
|
||||
//! #[validate(length(min = 1, max = 10))]
|
||||
//! v1: String,
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use crate::HasValidate;
|
||||
use axum_yaml::Yaml;
|
||||
|
||||
Reference in New Issue
Block a user