4 stable releases
1.1.2 | Sep 11, 2022 |
---|---|
1.1.0 | Feb 5, 2022 |
1.0.3 | Jul 3, 2021 |
1.0.2 | May 8, 2021 |
1.0.0 |
|
#62 in Encoding
112,075 downloads per month
Used in 103 crates
(28 directly)
15KB
279 lines
Serde support for the HTTP crate
Adds ability to serialize and deserialize types from the HTTP crate.
If you want to serialize Request
or Response
, use into_parts()
and serialize their parts, and then rebuild them using their Builder
.
Usage
You must annotate fields with #[serde(with = "http_serde::<appropriate method>")]
.
#[derive(Serialize, Deserialize)]
struct MyStruct {
#[serde(with = "http_serde::method")]
method: Method,
#[serde(with = "http_serde::status_code")]
status: StatusCode,
#[serde(with = "http_serde::uri")]
uri: Uri,
#[serde(with = "http_serde::header_map")]
headers: HeaderMap,
#[serde(with = "http_serde::authority")]
authority: Authority,
}
Requirements
- Rust 1.41 or later.
lib.rs
:
Adds ability to serialize and deserialize types from the HTTP crate.
If you want to serialize Request
or Response
, use into_parts()
and serialize their parts, and then rebuild them using their Builder
.
Usage
You must annotate fields with #[serde(with = "http_serde::<appropriate method>")]
.
# use serde::*;
# use http::*;
# use http::uri::*;
# use ::http_serde;
#[derive(Serialize, Deserialize)]
struct MyStruct {
#[serde(with = "http_serde::method")]
method: Method,
#[serde(with = "http_serde::status_code")]
status: StatusCode,
#[serde(with = "http_serde::uri")]
uri: Uri,
#[serde(with = "http_serde::header_map")]
headers: HeaderMap,
#[serde(with = "http_serde::authority")]
authority: Authority,
}
Dependencies
~1.2–1.9MB
~40K SLoC