When used as an extractor, it can deserialize request bodies into some type that implements [serde::Deserialize
]. If the request body cannot be parsed, or it does not contain the Content-Type: application/yaml
header, it will reject the request and return a 400 Bad Request
response.
```rust use axum::{ extract, routing::post, Router, }; use serde::Deserialize; use axum_yaml::Yaml;
struct CreateUser { email: String, password: String, }
async fn create_user(Yaml(payload): YamlCreateUser
}
let app = Router::new().route("/users", post(createuser)); async { axum::Server::bind(&"".parse().unwrap()).serve(app.intomake_service()).await.unwrap(); }; ```
When used as a response, it can serialize any type that implements [serde::Serialize
] to YAML
, and will automatically set Content-Type: application/yaml
header.
```rust use axum::{ extract::Path, routing::get, Router, }; use serde::Serialize; use uuid::Uuid; use axum_yaml::Yaml;
struct User { id: Uuid, username: String, }
async fn getuser(Path(userid) : Path
async fn finduser(userid: Uuid) -> User { // ... # unimplemented!() }
let app = Router::new().route("/users/:id", get(getuser)); async { axum::Server::bind(&"".parse().unwrap()).serve(app.intomake_service()).await.unwrap(); }; ```
This project is licensed under the MIT license