2018-06-28 15:55:15 +00:00
|
|
|
#![feature(plugin, decl_macro, proc_macro_non_items)]
|
2017-02-08 03:40:14 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
2018-06-28 15:55:15 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2017-02-08 03:40:14 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-03-22 09:02:37 +00:00
|
|
|
#[get("/<id>", format = "msgpack")]
|
2017-02-08 03:40:14 +00:00
|
|
|
fn get(id: usize) -> MsgPack<Message> {
|
|
|
|
MsgPack(Message {
|
|
|
|
id: id,
|
|
|
|
contents: "Hello, world!".to_string(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-22 09:02:37 +00:00
|
|
|
#[post("/", data = "<data>", format = "msgpack")]
|
2017-02-08 03:40:14 +00:00
|
|
|
fn create(data: MsgPack<Message>) -> Result<String, ()> {
|
|
|
|
Ok(data.into_inner().contents)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rocket() -> rocket::Rocket {
|
|
|
|
rocket::ignite()
|
|
|
|
.mount("/message", routes![get, create])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
rocket().launch();
|
|
|
|
}
|