1use haro::{Application, Request, Response};
2use serde_json::json;
3
4fn main() {
5 let app = build_app();
6 app.run();
7}
8
9fn build_app() -> Application {
10 let mut app = Application::new("0:8080");
11 app.route("/", index);
12 app.route("/hello/:name", hello);
13
14 app
15}
16
17fn index(_: Request) -> Response {
18 Response::str("Hello Haro")
19}
20
21fn hello(req: Request) -> Response {
22 let data = json!({
23 "method":req.method(),
24 "args":req.args,
25 "params":req.params,
26 "data":req.data,
27 });
28 Response::json(data)
29}
30
31#[cfg(test)]
32mod tests {
33 use std::collections::HashMap;
34
35 use super::build_app;
36
37 #[test]
38 fn it_works() {
39 let app = build_app();
40 let res = app.request("get", "/", HashMap::new(), &Vec::new());
41 assert_eq!("Hello Haro".as_bytes(), res.body());
42 }
43}