diff --git a/.travis.yml b/.travis.yml index b72da2c8d..3c55bbde6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,8 @@ script: - | if [[ "$TRAVIS_RUST_VERSION" == "1.20.0" ]]; then + cd examples/basics && cargo check && cd ../.. + cd examples/hello-world && cargo check && cd ../.. cd examples/multipart && cargo check && cd ../.. cd examples/json && cargo check && cd ../.. cd examples/template_tera && cargo check && cd ../.. diff --git a/Cargo.toml b/Cargo.toml index 316ba9ef3..7a106be6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,9 +103,10 @@ opt-level = 3 [workspace] members = [ "./", - "examples/basic", + "examples/basics", "examples/diesel", "examples/json", + "examples/hello-world", "examples/multipart", "examples/signals", "examples/state", diff --git a/examples/basic/Cargo.toml b/examples/basics/Cargo.toml similarity index 93% rename from examples/basic/Cargo.toml rename to examples/basics/Cargo.toml index d4fc56662..b5eefd0f3 100644 --- a/examples/basic/Cargo.toml +++ b/examples/basics/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "basic" +name = "basics" version = "0.1.0" authors = ["Nikolay Kim "] workspace = "../.." diff --git a/examples/basic/README.md b/examples/basics/README.md similarity index 100% rename from examples/basic/README.md rename to examples/basics/README.md diff --git a/examples/basic/src/main.rs b/examples/basics/src/main.rs similarity index 100% rename from examples/basic/src/main.rs rename to examples/basics/src/main.rs diff --git a/examples/hello-world/Cargo.toml b/examples/hello-world/Cargo.toml new file mode 100644 index 000000000..63bb6f6a4 --- /dev/null +++ b/examples/hello-world/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "hello-world" +version = "0.1.0" +authors = ["Nikolay Kim "] +workspace = "../.." + +[dependencies] +env_logger = "0.4" +actix = "^0.3.5" +actix-web = { path = "../../" } diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs new file mode 100644 index 000000000..5f1484bd2 --- /dev/null +++ b/examples/hello-world/src/main.rs @@ -0,0 +1,28 @@ +extern crate actix; +extern crate actix_web; +extern crate env_logger; + +use actix_web::*; + + +fn index(_req: HttpRequest) -> &'static str { + "Hello world!" +} + +fn main() { + ::std::env::set_var("RUST_LOG", "actix_web=info"); + let _ = env_logger::init(); + let sys = actix::System::new("ws-example"); + + let _addr = HttpServer::new( + || Application::new() + // enable logger + .middleware(middleware::Logger::default()) + .resource("/index.html", |r| r.f(|_| "Hello world!")) + .resource("/", |r| r.f(index))) + .bind("127.0.0.1:8080").unwrap() + .start(); + + println!("Started http server: 127.0.0.1:8080"); + let _ = sys.run(); +}