axum-yaml

Features

Usage Example

Extractor example

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;

[derive(Deserialize)]

struct CreateUser { email: String, password: String, }

async fn create_user(Yaml(payload): Yaml) { // payload is a CreateUser }

let app = Router::new().route("/users", post(createuser)); async { axum::Server::bind(&"".parse().unwrap()).serve(app.intomake_service()).await.unwrap(); }; ```

Response example

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;

[derive(Serialize)]

struct User { id: Uuid, username: String, }

async fn getuser(Path(userid) : Path) -> Yaml { let user = finduser(userid).await; Yaml(user) }

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(); }; ```

License

This project is licensed under the MIT license