[closes #2] removed hello world endpoints
parent
c0311132ec
commit
89bd29dc78
|
@ -1,21 +0,0 @@
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
pub fn routes() -> Vec<rocket::Route> {
|
|
||||||
routes![world, hello, name_age]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/world")]
|
|
||||||
fn world() -> &'static str {
|
|
||||||
"Hello, world!"
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/<name>")]
|
|
||||||
fn hello(name: String) -> String {
|
|
||||||
format!("Hello, {}", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/world?<name>&<age>")]
|
|
||||||
fn name_age(name: String, age: u16) -> String {
|
|
||||||
format!("Hello, {} who is {} years old!", name, age)
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
use rocket::http::Status;
|
|
||||||
use rocket::local::Client;
|
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
|
||||||
rocket::ignite().mount("/", super::routes())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_world() {
|
|
||||||
let client = Client::new(rocket()).expect("valid rocket instance");
|
|
||||||
let mut response = client.get("/world").dispatch();
|
|
||||||
|
|
||||||
assert_eq!(response.status(), Status::Ok);
|
|
||||||
assert_eq!(response.body_string(), Some("Hello, world!".into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_hello() {
|
|
||||||
let client = Client::new(rocket()).expect("valid rocket instance");
|
|
||||||
let mut response = client.get("/thisisaname").dispatch();
|
|
||||||
|
|
||||||
assert_eq!(response.status(), Status::Ok);
|
|
||||||
assert_eq!(response.body_string(), Some("Hello, thisisaname".into()));
|
|
||||||
}
|
|
|
@ -6,12 +6,10 @@ extern crate rocket;
|
||||||
// Route modules
|
// Route modules
|
||||||
mod catchers;
|
mod catchers;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod hello;
|
|
||||||
mod ivago;
|
mod ivago;
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
fn rocket() -> rocket::Rocket {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.mount("/hello", hello::routes())
|
|
||||||
.mount("/ivago", ivago::routes())
|
.mount("/ivago", ivago::routes())
|
||||||
.register(catchers![catchers::not_found])
|
.register(catchers![catchers::not_found])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue