malaga_http_utils
is a small library to handler request and response objects
https://docs.rs/malagahttputils/0.1.2/malagahttputils/
```rust
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
}
}
struct TestHeader {
#[serde(rename = "Content-Type")]
content_type: String,
#[serde(rename = "Authorization")]
pub authorization: String,
}
struct Body { user: String, }
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
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") } }); } ```
Malaga HTTP Utils is MIT licensed. See license