#http #http-header

http-serde

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

9 stable releases

2.1.1 May 27, 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

#152 in Encoding

Download history 96132/week @ 2024-06-11 90741/week @ 2024-06-18 84045/week @ 2024-06-25 71333/week @ 2024-07-02 73273/week @ 2024-07-09 74269/week @ 2024-07-16 82040/week @ 2024-07-23 84451/week @ 2024-07-30 83559/week @ 2024-08-06 73549/week @ 2024-08-13 82166/week @ 2024-08-20 82072/week @ 2024-08-27 82024/week @ 2024-09-03 75417/week @ 2024-09-10 71344/week @ 2024-09-17 72257/week @ 2024-09-24

312,170 downloads per month
Used in 177 crates (51 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
~17K SLoC