1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 01:51:23 +02:00

renamed Route::handler to Route::f, added Route::h to register Handler

This commit is contained in:
Nikolay Kim
2017-12-04 14:07:53 -08:00
parent 03f7d95d88
commit f5d6179a34
19 changed files with 79 additions and 40 deletions

View File

@ -77,8 +77,8 @@ fn main() {
.header("X-Version", "0.2")
.finish())
.resource("/test", |r| {
r.method(Method::GET).handler(|req| httpcodes::HTTPOk);
r.method(Method::HEAD).handler(|req| httpcodes::HTTPMethodNotAllowed);
r.method(Method::GET).f(|req| httpcodes::HTTPOk);
r.method(Method::HEAD).f(|req| httpcodes::HTTPMethodNotAllowed);
})
.finish();
}

View File

@ -2,7 +2,8 @@
## Individual file
It is possible to serve static files with tail path pattern and `NamedFile`.
It is possible to serve static files with custom path pattern and `NamedFile`. To
match path tail we can use `.*` regex.
```rust
extern crate actix_web;
@ -16,7 +17,7 @@ fn index(req: HttpRequest) -> Result<fs::NamedFile> {
fn main() {
Application::default("/")
.resource(r"/a/{tail:*}", |r| r.method(Method::GET).handler(index))
.resource(r"/a/{tail:.*}", |r| r.method(Method::GET).f(index))
.finish();
}
```

View File

@ -49,7 +49,7 @@ request handler with the application's `resource` on a particular *HTTP method*
# }
# fn main() {
let app = Application::default("/")
.resource("/", |r| r.method(Method::GET).handler(index))
.resource("/", |r| r.method(Method::GET).f(index))
.finish();
# }
```
@ -80,7 +80,7 @@ fn main() {
HttpServer::new(
Application::default("/")
.resource("/", |r| r.route().handler(index)))
.resource("/", |r| r.route().f(index)))
.serve::<_, ()>("127.0.0.1:8088").unwrap();
println!("Started http server: 127.0.0.1:8088");

View File

@ -21,7 +21,7 @@ has same url path prefix:
# }
# fn main() {
let app = Application::default("/prefix")
.resource("/index.html", |r| r.method(Method::GET).handler(index))
.resource("/index.html", |r| r.method(Method::GET).f(index))
.finish()
# }
```
@ -41,13 +41,13 @@ use tokio_core::net::TcpStream;
fn main() {
HttpServer::<TcpStream, SocketAddr, _>::new(vec![
Application::default("/app1")
.resource("/", |r| r.route().handler(|r| httpcodes::HTTPOk))
.resource("/", |r| r.route().f(|r| httpcodes::HTTPOk))
.finish(),
Application::default("/app2")
.resource("/", |r| r.route().handler(|r| httpcodes::HTTPOk))
.resource("/", |r| r.route().f(|r| httpcodes::HTTPOk))
.finish(),
Application::default("/")
.resource("/", |r| r.route().handler(|r| httpcodes::HTTPOk))
.resource("/", |r| r.route().f(|r| httpcodes::HTTPOk))
.finish(),
]);
}

View File

@ -79,7 +79,7 @@ fn main() {
HttpServer::new(
Application::default("/")
.resource("/", |r| r.method(
Method::GET).handler(|req| {MyObj{name: "user".to_owned()}})))
Method::GET).f(|req| {MyObj{name: "user".to_owned()}})))
.serve::<_, ()>("127.0.0.1:8088").unwrap();
println!("Started http server: 127.0.0.1:8088");

View File

@ -55,8 +55,8 @@ if no route could be matched default response `HTTPMethodNotAllowed` get resturn
fn main() {
Application::default("/")
.resource("/prefix", |r| {
r.method(Method::GET).handler(|r| httpcodes::HTTPOk);
r.method(Method::POST).handler(|r| httpcodes::HTTPForbidden);
r.method(Method::GET).h(httpcodes::HTTPOk);
r.method(Method::POST).h(httpcodes::HTTPForbidden);
})
.finish();
}
@ -87,7 +87,7 @@ fn index(req: HttpRequest) -> String {
fn main() {
Application::default("/")
.resource("/{name}", |r| r.method(Method::GET).handler(index))
.resource("/{name}", |r| r.method(Method::GET).f(index))
.finish();
}
```
@ -105,7 +105,7 @@ You can also specify a custom regex in the form `{identifier:regex}`:
fn main() {
Application::default("/")
.resource(r"{name:\d+}", |r| r.method(Method::GET).handler(index))
.resource(r"{name:\d+}", |r| r.method(Method::GET).f(index))
.finish();
}
```
@ -126,7 +126,7 @@ fn index(req: HttpRequest) -> Result<String> {
fn main() {
Application::default("/")
.resource(r"/a/{v1}/{v2}/", |r| r.route().handler(index))
.resource(r"/a/{v1}/{v2}/", |r| r.route().f(index))
.finish();
}
```
@ -138,7 +138,7 @@ It is possible to match path tail with custom `.*` regex.
```rust,ignore
fn main() {
Application::default("/")
.resource(r"/test/{tail:.*}", |r| r.method(Method::GET).handler(index))
.resource(r"/test/{tail:.*}", |r| r.method(Method::GET).f(index))
.finish();
}
```
@ -174,7 +174,7 @@ fn index(req: HttpRequest) -> Result<String> {
fn main() {
Application::default("/")
.resource(r"/a/{tail:.*}", |r| r.method(Method::GET).handler(index))
.resource(r"/a/{tail:.*}", |r| r.method(Method::GET).f(index))
.finish();
}
```

View File

@ -30,7 +30,7 @@ fn index(req: HttpRequest<AppState>) -> String {
fn main() {
Application::build("/", AppState{counter: Cell::new(0)})
.resource("/", |r| r.method(Method::GET).handler(index))
.resource("/", |r| r.method(Method::GET).f(index))
.finish();
}
```

View File

@ -54,7 +54,7 @@ fn index(req: HttpRequest) -> Result<Json<MyObj>> {
fn main() {
Application::default("/")
.resource(r"/a/{name}", |r| r.method(Method::GET).handler(index))
.resource(r"/a/{name}", |r| r.method(Method::GET).f(index))
.finish();
}
```