Crates.io | axum-msgpack |
lib.rs | axum-msgpack |
version | |
source | src |
created_at | 2021-08-28 12:51:08.652657 |
updated_at | 2025-01-05 01:37:08.014769 |
description | serialize/derserialize msgpack for axum |
homepage | |
repository | |
max_upload_size | |
id | 443442 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
axum-msgpack
adds MessagePack features to axum.
More information about this crate can be found in the crate documentation.
Serialize, Deserialize MessagePack from request/response
use axum_msgpack::MsgPack;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct User {
pub name: String,
#[serde(with = "serde_bytes")]
pub data: Vec<u8>
}
// axum handler | MsgPack
async fn get_handler() -> MsgPack<User> {
let user = User {
name: "steve".to_string(),
data: vec![0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
};
MsgPack(user)
}
// axum handler | MsgPack
async fn post_handler(MsgPack(user): MsgPack<User>) -> Html<String> {
let string = format!("<h1>{:?}</h1>", user.name);
Html(string)
}
// axum handler | MsgPackRaw
async fn get_handler_raw() -> MsgPackRaw<User> {
let user = User {
name: "steve".to_string(),
data: vec![0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
};
MsgPackRaw(user)
}
// axum handler | MsgPackRaw
async fn post_handler_raw(MsgPackRaw(user): MsgPackRaw<User>) -> Html<String> {
let string = format!("<h1>{:?}</h1>", user.name);
Html(string)
}
Dependencies for serializing/deserializing MsgPack
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11"
In order to pack arrays correct remember to add #[serde(with = "serde_bytes")]
to the struct member.
This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
This project is licensed under the MIT license.