2 releases
Uses new Rust 2024
new 0.1.1 | Mar 19, 2025 |
---|---|
0.1.0 | Mar 19, 2025 |
#745 in Encoding
13KB
216 lines
poem-typed-multipart
This crate provides a rust-native, typesafe extractor for multipart bodies in poem. Check the crate documentation for more information.
Contributing
Any contributions are welcome. Just fork the repository and create a PR with your changes.
License
Licensed under the MIT Licence
lib.rs
:
This crate provides a typed extractor for multipart/form-data requests in poem
, in a
rust-native manner.
Usage
To use this crate, either implement FromMultiPart
for your structure, or use the
poem_typed_multipart_macro::FromMultiPart
macro. Then use the TypedMultiPart
extractor
in your endpoint.
use poem_typed_multipart::{TypedMultiPart, FromMultiPart}
#[derive(Debug, FromMultiPart)]
struct Body {
id: u32,
title: String
}
#[poem::handler]
fn hello(TypedMultiPart(body): TypedMultiPart<Body>) -> String {
println!("{body:?}");
format!("Hello {}", body.title)
}
Extending this crate to your types
All types implementing part::FromMultiPartPart
can be used to can be extracted using this
crate. Check the existing implementation on details how to implement these yourself.
Features
json
: Extract json values using thepart::Json
type.bytes
: Support forbytes::Bytes
.
Dependencies
~17–29MB
~520K SLoC