Malaga HTTP Utils

malaga_http_utils is a small library to handler request and response objects

Documentation

https://docs.rs/malagahttputils/0.1.2/malagahttputils/

Example:

```rust

[macro_use]

extern crate serde_derive;

extern crate serdejson; extern crate serde; extern crate bincode; extern crate malagahttp_utils;

use malagahttputils::{HttpObj, utils::*}; use std::str;

impl HttpObj for TestReq { fn serializetostruct(req: &[u8]) -> Self { let reqstring = str::fromutf8(req).unwrap(); let serreq: TestReq = serdejson::fromstr(reqstring).unwrap();

   ser_req

}

fn serialize_to_binary(req: TestReq) -> Vec<u8> {
    let ser_req: Vec<u8> = bincode::serialize(&req).unwrap();

    ser_req
}

}

[derive(Serialize, Deserialize, Debug, PartialEq)]

struct TestHeader {
    #[serde(rename = "Content-Type")]
    content_type: String,
    #[serde(rename = "Authorization")]
    pub authorization: String,
}

[derive(Serialize, Deserialize, Debug, PartialEq)]

struct Body { user: String, }

[derive(Serialize, Deserialize, Debug, PartialEq)]

struct TestReq { headers: TestHeader, method: Methods, body: Body, }

fn main() { let resq = b"{ \"headers\": { \"Content-Type\": \"application/json\", \"Authorization\": \"Basis 1ddmcdd\" }, \"method\": \"POST\", \"body\": { \"user\":\"test\" } }";

let resqstructser: TestReq = TestReq::serializetostruct(resq); let resqbinaryser: Vec = TestReq::serializetobinary(resqstructser); let reqstring: TestReq = bincode::deserialize(&resqbinary_ser[..]).unwrap();

asserteq!(reqstring, TestReq{ headers: TestHeader { content_type: String::from("application/json"), authorization: String::from("Basis 1ddmcdd"), }, method: Methods::POST, body: Body { user: String::from("test") } }); } ```

License

Malaga HTTP Utils is MIT licensed. See license