#http #serde #deserialize #status #url

http-serde

Serde support for the http crate. (De)serialize HeaderMap, Uri, Method, StatusCode

4 stable releases

1.0.3 Jul 3, 2021
1.0.2 May 8, 2021
1.0.1 Mar 15, 2020
1.0.0 Feb 9, 2020

#108 in Encoding

Download history 2572/week @ 2021-04-05 2810/week @ 2021-04-12 2916/week @ 2021-04-19 2854/week @ 2021-04-26 2737/week @ 2021-05-03 2993/week @ 2021-05-10 3900/week @ 2021-05-17 4992/week @ 2021-05-24 4250/week @ 2021-05-31 4377/week @ 2021-06-07 4799/week @ 2021-06-14 4904/week @ 2021-06-21 4806/week @ 2021-06-28 4116/week @ 2021-07-05 4997/week @ 2021-07-12 4914/week @ 2021-07-19

16,162 downloads per month
Used in 16 crates (5 directly)

Apache-2.0 OR MIT

12KB
213 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,
}

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_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,
}

Dependencies

~1.1–1.8MB
~38K SLoC