http-serde

Crates.iohttp-serde
lib.rshttp-serde
version2.1.0
sourcesrc
created_at2020-02-09 16:35:46.166444
updated_at2024-04-12 18:45:17.205475
descriptionSerde support for the http crate. (De)serialize HeaderMap, Uri, Method, StatusCode
homepagehttps://lib.rs/crates/http-serde
repositoryhttps://gitlab.com/kornelski/http-serde
max_upload_size
id206750
size32,141
Kornel (kornelski)

documentation

README

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.
Commit count: 30

cargo fmt