2016-03-22 23:27:12 +00:00
|
|
|
extern crate rocket;
|
|
|
|
|
2016-10-04 02:37:49 +00:00
|
|
|
use rocket::{Request, Response, Route};
|
2016-10-04 00:09:13 +00:00
|
|
|
use rocket::http::Method::*;
|
2016-03-22 23:27:12 +00:00
|
|
|
|
2016-08-26 08:55:11 +00:00
|
|
|
fn root<'r>(req: &'r Request<'r>) -> Response<'r> {
|
2016-03-22 23:28:45 +00:00
|
|
|
let name = req.get_param(0).unwrap_or("unnamed");
|
2016-03-22 23:27:12 +00:00
|
|
|
Response::new(format!("Hello, {}!", name))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2016-08-26 08:55:11 +00:00
|
|
|
fn echo_url<'a>(req: &'a Request<'a>) -> Response<'a> {
|
|
|
|
Response::new(req.uri().as_str().split_at(6).1)
|
2016-03-22 23:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2016-10-04 02:37:49 +00:00
|
|
|
let mut rocket = rocket::ignite();
|
2016-04-03 10:36:30 +00:00
|
|
|
|
2016-03-22 23:27:12 +00:00
|
|
|
let first = Route::new(Get, "/hello", root);
|
|
|
|
let second = Route::new(Get, "/hello/<any>", root);
|
2016-04-03 10:36:30 +00:00
|
|
|
rocket.mount("/", vec![first, second]);
|
|
|
|
|
|
|
|
let echo = Route::new(Get, "/", echo_url);
|
|
|
|
rocket.mount("/echo:<str>", vec![echo]);
|
2016-03-22 23:27:12 +00:00
|
|
|
|
2016-04-03 10:36:30 +00:00
|
|
|
rocket.launch();
|
2016-03-22 23:27:12 +00:00
|
|
|
}
|