1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 09:42:57 +01:00

move example/basic.rs to examples/basic

This commit is contained in:
ami44 2017-12-30 16:50:17 +01:00
parent a1dc5a6bd1
commit df393df547
4 changed files with 38 additions and 3 deletions

View File

@ -47,7 +47,7 @@ Some basic benchmarks could be found in this [respository](https://github.com/fa
## Examples
* [Basic](https://github.com/actix/actix-web/tree/master/examples/basic.rs)
* [Basic](https://github.com/actix/actix-web/tree/master/examples/basic/)
* [Stateful](https://github.com/actix/actix-web/tree/master/examples/state.rs)
* [Mulitpart streams](https://github.com/actix/actix-web/tree/master/examples/multipart/)
* [Simple websocket session](https://github.com/actix/actix-web/tree/master/examples/websocket.rs)

10
examples/basic/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "basic"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
[dependencies]
futures = "*"
env_logger = "0.4"
actix = "^0.3.5"
actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] }

19
examples/basic/README.md Normal file
View File

@ -0,0 +1,19 @@
# basic
## Usage
### server
```bash
cd actix-web/examples/basic
cargo run
# Started http server: 127.0.0.1:8080
```
### web client
- [http://localhost:8080/index.html](http://localhost:8080/index.html)
- [http://localhost:8080/async/bob](http://localhost:8080/async/bob)
- [http://localhost:8080/user/bob/](http://localhost:8080/user/bob/) plain/text download
- [http://localhost:8080/test](http://localhost:8080/test) (return status switch GET or POST or other)
- [http://localhost:8080/static/index.html](http://localhost:8080/static/index.html)

View File

@ -8,6 +8,8 @@ extern crate futures;
use futures::Stream;
use actix_web::*;
use actix::Arbiter;
use actix::actors::signal::{ProcessSignals, Subscribe};
use actix_web::middleware::RequestSession;
use futures::future::{FutureResult, result};
@ -57,7 +59,7 @@ fn main() {
let _ = env_logger::init();
let sys = actix::System::new("basic-example");
HttpServer::new(
let addr = HttpServer::new(
|| Application::new()
// enable logger
.middleware(middleware::Logger::default())
@ -82,7 +84,7 @@ fn main() {
}))
// static files
.resource("/static/{tail:.*}",
|r| r.h(fs::StaticFiles::new("tail", "examples/static/", true)))
|r| r.h(fs::StaticFiles::new("tail", "../static/", true)))
// redirect
.resource("/", |r| r.method(Method::GET).f(|req| {
println!("{:?}", req);
@ -94,6 +96,10 @@ fn main() {
.bind("0.0.0.0:8080").unwrap()
.start();
// Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
println!("Starting http server: 127.0.0.1:8080");
let _ = sys.run();
}