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

guide update

This commit is contained in:
Nikolay Kim
2017-12-18 18:56:58 -08:00
parent e9a3845e26
commit 2124730e0a
3 changed files with 73 additions and 37 deletions

View File

@ -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
}
```