#http #deserialize #serde #http-header #status #url #serde-derive

http-serde

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

8 stable releases

2.1.0 Apr 12, 2024
2.0.0 Nov 20, 2023
1.1.3 Aug 18, 2023
1.1.2 Sep 11, 2022
1.0.1 Mar 15, 2020

#77 in Encoding

Download history 53058/week @ 2024-01-02 55720/week @ 2024-01-09 60104/week @ 2024-01-16 63513/week @ 2024-01-23 63067/week @ 2024-01-30 61157/week @ 2024-02-06 68982/week @ 2024-02-13 68196/week @ 2024-02-20 68669/week @ 2024-02-27 74078/week @ 2024-03-05 78010/week @ 2024-03-12 74168/week @ 2024-03-19 67464/week @ 2024-03-26 75204/week @ 2024-04-02 73946/week @ 2024-04-09 68783/week @ 2024-04-16

298,651 downloads per month
Used in 162 crates (48 directly)

Apache-2.0 OR MIT

22KB
441 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>")].

# use http::{*, uri::*};
#[derive(serde::Serialize, serde::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,
}

There's also support for the types wrapped in an Option. To use it, change the with attribute prefix from http_serde:: to http_serde::option::.

# use http::{*, uri::*};
#[derive(serde::Serialize, serde::Deserialize)]
struct MyStruct {
    #[serde(with = "http_serde::option::header_map")]
    //                          ^^^^^^
    optional_headers: Option<HeaderMap>,
}

Requirements

  • Rust 1.56 or later.

Dependencies

~0.7–1MB
~18K SLoC