mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
guide update
This commit is contained in:
@ -1,5 +1,33 @@
|
||||
# Server
|
||||
|
||||
[*HttpServer*](../actix_web/struct.HttpServer.html) type is responsible for
|
||||
serving http requests. *HttpServer* accept applicaiton factory as a parameter,
|
||||
Application factory must have `Send` + `Sync` bounderies. More about that in
|
||||
*multi-threading* section. To bind to specific socket address `bind()` must be used.
|
||||
This method could be called multiple times. To start http server one of the *start*
|
||||
methods could be used. `start()` method start simple server, `start_tls()` or `start_ssl()`
|
||||
starts ssl server. *HttpServer* is an actix actor, it has to be initialized
|
||||
within properly configured actix system:
|
||||
|
||||
```rust
|
||||
# extern crate actix;
|
||||
# extern crate actix_web;
|
||||
use actix::*;
|
||||
use actix_web::*;
|
||||
|
||||
fn main() {
|
||||
let sys = actix::System::new("guide");
|
||||
|
||||
HttpServer::new(
|
||||
|| Application::new()
|
||||
.resource("/", |r| r.f(|_| httpcodes::HTTPOk)))
|
||||
.bind("127.0.0.1:59080").unwrap()
|
||||
.start().unwrap();
|
||||
|
||||
# actix::Arbiter::system().send(actix::msgs::SystemExit(0));
|
||||
let _ = sys.run();
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Multi-threading
|
||||
@ -18,7 +46,7 @@ use actix_web::*;
|
||||
fn main() {
|
||||
HttpServer::<TcpStream, SocketAddr, _, _>::new(
|
||||
|| Application::new()
|
||||
.resource("/", |r| r.f(|r| httpcodes::HTTPOk)))
|
||||
.resource("/", |r| r.f(|_| httpcodes::HTTPOk)))
|
||||
.threads(4); // <- Start 4 threads
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user