use oker::{App, HttpResponse, Request, RequestType};

fn main() {
    let mut app = App::new(Box::new(|_req: &Request| {
        HttpResponse::Html("<h1>hello</h1>".to_string())
    }));

    app.route(
        RequestType::GET,
        "/json".to_string(),
        Box::new(|_req: &Request| {
            HttpResponse::Json("{\"msg\":\"world\"}".to_string())
        }),
    );

    app.route(
        RequestType::GET,
        "/xml".to_string(),
        Box::new(|_req: &Request| HttpResponse::Xml("<msg>world</msg>".to_string())),
    );

    // Query parameter example: /greet?name=oker
    app.route(
        RequestType::GET,
        "/greet".to_string(),
        Box::new(|req: &Request| {
            let name = req.query_param("name").unwrap_or("world");
            HttpResponse::Html(format!("<h1>hello {}</h1>", name))
        }),
    );

    // Start the server (press 'q' to quit).
    app.start();
}
