📬 postcard axum extractor and response using serde
RustGPL-3.0
📬 postcard axum extractor and response using serde
Example
Request
use axum::{extract, routing::post,Router};use serde::Deserialize;use axum_postcard::Postcard;#[derive(Deserialize)]structCreateUser{email:String,password:String,}asyncfncreate_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)]structUser{id:u32,username:String,}asyncfnget_user(Path(user_id):Path<u32>) -> Postcard<User>{let user = find_user(user_id).await;Postcard(user)}asyncfnfind_user(user_id:u32) -> User{todo!()}