2018-06-28 15:55:15 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2017-02-08 03:40:14 +00:00
|
|
|
#[macro_use] extern crate serde_derive;
|
|
|
|
|
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
2018-10-07 00:24:11 +00:00
|
|
|
use rocket_contrib::msgpack::MsgPack;
|
2017-02-08 03:40:14 +00:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2018-09-20 04:14:30 +00:00
|
|
|
struct Message<'r> {
|
2017-02-08 03:40:14 +00:00
|
|
|
id: usize,
|
2018-09-20 04:14:30 +00:00
|
|
|
contents: &'r str
|
2017-02-08 03:40:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:02:37 +00:00
|
|
|
#[get("/<id>", format = "msgpack")]
|
2018-09-20 04:14:30 +00:00
|
|
|
fn get(id: usize) -> MsgPack<Message<'static>> {
|
|
|
|
MsgPack(Message { id: id, contents: "Hello, world!", })
|
2017-02-08 03:40:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:02:37 +00:00
|
|
|
#[post("/", data = "<data>", format = "msgpack")]
|
2019-06-13 02:41:29 +00:00
|
|
|
fn create(data: MsgPack<Message<'_>>) -> String {
|
2018-09-20 04:14:30 +00:00
|
|
|
data.contents.to_string()
|
2017-02-08 03:40:14 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 12:01:26 +00:00
|
|
|
#[rocket::launch]
|
2017-02-08 03:40:14 +00:00
|
|
|
fn rocket() -> rocket::Rocket {
|
2018-09-20 04:14:30 +00:00
|
|
|
rocket::ignite().mount("/message", routes![get, create])
|
2017-02-08 03:40:14 +00:00
|
|
|
}
|