use web_net::{App, Route, get};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = App::builder()
.host("127.0.0.1:8091")
.development()
.base("/app")
.route(get("/", |cx| {
let users = cx.url("/users/7")?;
cx.html(
200,
&format!("<h1>Hello</h1><a href=\"{users}\">user 7</a>"),
)
}))
.route(get("/users/:id", |cx| {
let id: u64 = cx.param_as("id")?;
cx.text(200, &format!("user {id}"))
}))
.route(
Route::at("/contact")
.get(|cx| cx.html(200, "<form method=post><button>Send</button></form>"))
.post(|cx| cx.redirect(303, "/"))
.csrf_exempt("demo: the POST changes nothing"),
)
.build()?;
println!("listening on http://127.0.0.1:8091/app/");
app.listen("127.0.0.1:8091")?.wait();
Ok(())
}