1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

use Route for Applicaiton handlers

This commit is contained in:
Nikolay Kim
2017-12-04 14:53:40 -08:00
parent f5d6179a34
commit e332c1242f
16 changed files with 61 additions and 80 deletions

View File

@ -66,8 +66,8 @@ fn main() {
.secure(false)
.finish()
))
// register simple handle r, handle all methods
.handler("/index.html", index)
// register simple route, handle all methods
.route("/index.html", |r| r.f(index))
// with path parameters
.resource("/user/{name}/", |r| r.route().method(Method::GET).f(with_param))
// async handler
@ -81,15 +81,15 @@ fn main() {
.header("LOCATION", "/index.html")
.body(Body::Empty)
}))
.handler("/test", |req| {
.route("/test", |r| r.f(|req| {
match *req.method() {
Method::GET => httpcodes::HTTPOk,
Method::POST => httpcodes::HTTPMethodNotAllowed,
_ => httpcodes::HTTPNotFound,
}
})
}))
// static files
.route("/static", fs::StaticFiles::new("examples/static/", true)))
.route("/static", |r| r.h(fs::StaticFiles::new("examples/static/", true))))
.serve::<_, ()>("127.0.0.1:8080").unwrap();
println!("Started http server: 127.0.0.1:8080");

View File

@ -69,7 +69,7 @@ fn main() {
.method(Method::GET)
.f(|req| ws::start(req, MyWebSocket{counter: 0})))
// register simple handler, handle all methods
.handler("/", index))
.route("/", |r| r.f(index)))
.serve::<_, ()>("127.0.0.1:8080").unwrap();
println!("Started http server: 127.0.0.1:8080");

View File

@ -67,7 +67,7 @@ fn main() {
// websocket route
.resource("/ws/", |r| r.route().method(Method::GET).f(ws_index))
// static files
.route("/", fs::StaticFiles::new("examples/static/", true)))
.route("/", |r| r.h(fs::StaticFiles::new("examples/static/", true))))
// start http server on 127.0.0.1:8080
.serve::<_, ()>("127.0.0.1:8080").unwrap();