mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-24 22:37:35 +02:00
http server accepts factory of HttpHandlers
This commit is contained in:
@ -55,10 +55,10 @@ request handler with the application's `resource` on a particular *HTTP method*
|
||||
```
|
||||
|
||||
After that, application instance can be used with `HttpServer` to listen for incoming
|
||||
connections:
|
||||
connections. Server accepts function that should return `HttpHandler` instance:
|
||||
|
||||
```rust,ignore
|
||||
HttpServer::new(app).serve::<_, ()>("127.0.0.1:8088");
|
||||
HttpServer::new(|| app).serve::<_, ()>("127.0.0.1:8088");
|
||||
```
|
||||
|
||||
That's it. Now, compile and run the program with cargo run.
|
||||
@ -79,7 +79,7 @@ fn main() {
|
||||
let sys = actix::System::new("example");
|
||||
|
||||
HttpServer::new(
|
||||
Application::new()
|
||||
|| Application::new()
|
||||
.resource("/", |r| r.f(index)))
|
||||
.serve::<_, ()>("127.0.0.1:8088").unwrap();
|
||||
|
||||
|
@ -42,7 +42,7 @@ Multiple applications could be served with one server:
|
||||
use actix_web::*;
|
||||
|
||||
fn main() {
|
||||
HttpServer::<TcpStream, SocketAddr, _>::new(vec![
|
||||
HttpServer::<TcpStream, SocketAddr, _>::new(|| vec![
|
||||
Application::new()
|
||||
.prefix("/app1")
|
||||
.resource("/", |r| r.f(|r| httpcodes::HTTPOk)),
|
||||
|
@ -81,7 +81,7 @@ fn main() {
|
||||
let sys = actix::System::new("example");
|
||||
|
||||
HttpServer::new(
|
||||
Application::new()
|
||||
|| Application::new()
|
||||
.resource("/", |r| r.method(Method::GET).f(index)))
|
||||
.serve::<_, ()>("127.0.0.1:8088").unwrap();
|
||||
|
||||
|
Reference in New Issue
Block a user