#axum #postcard #serde #post #response #extractor #request

axum-postcard

📬 postcard axum extractor and response using serde

3 unstable releases

0.2.0 Sep 26, 2024
0.1.1 Feb 10, 2024
0.1.0 Feb 10, 2024

#643 in Encoding

Download history 176/week @ 2024-09-23 28/week @ 2024-09-30 7/week @ 2024-10-07 9/week @ 2024-10-14

220 downloads per month

GPL-3.0-only

17KB
180 lines

📬 postcard axum extractor and response using serde

Example

Request

use axum::{extract, routing::post, Router};
use serde::Deserialize;
use axum_postcard::Postcard;

#[derive(Deserialize)]
struct CreateUser {
    email: String,
    password: String,
}

async fn create_user(
    Postcard(payload): Postcard<CreateUser>
) {
    // payload is a `CreateUser`
    todo!()
}

Response

use axum::{extract::Path, routing::get, Router};
use serde::Serialize;
use axum_postcard::Postcard;

#[derive(Serialize)]
struct User {
    id: u32,
    username: String,
}

async fn get_user(
    Path(user_id) : Path<u32>
) -> Postcard<User> {
    let user = find_user(user_id).await;
    Postcard(user)
}


async fn find_user(user_id: u32) -> User {
    todo!()
}

Dependencies

~6–13MB
~150K SLoC