#![feature(plugin, decl_macro)] #![plugin(rocket_codegen)] extern crate rocket; extern crate rocket_contrib; #[macro_use] extern crate serde_derive; #[cfg(test)] mod tests; use rocket_contrib::MsgPack; #[derive(Serialize, Deserialize)] struct Message { id: usize, contents: String } #[get("/", format = "msgpack")] fn get(id: usize) -> MsgPack { MsgPack(Message { id: id, contents: "Hello, world!".to_string(), }) } #[post("/", data = "", format = "msgpack")] fn create(data: MsgPack) -> Result { Ok(data.into_inner().contents) } fn rocket() -> rocket::Rocket { rocket::ignite() .mount("/message", routes![get, create]) } fn main() { rocket().launch(); }