axum-postcard

Crates.ioaxum-postcard
lib.rsaxum-postcard
version0.2.0
sourcesrc
created_at2024-02-10 17:05:17.25986
updated_at2024-09-26 01:42:14.075205
description📬 postcard axum extractor and response using serde
homepage
repositoryhttps://github.com/joseburgosguntin/axum-postcard/tree/main
max_upload_size
id1135070
size47,315
José Burgos Guntín (joseburgosguntin)

documentation

README

📬 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!()
}
Commit count: 0

cargo fmt