diff --git a/content/docs/getting-started.md b/content/docs/getting-started.md index c7b2770..bb68766 100644 --- a/content/docs/getting-started.md +++ b/content/docs/getting-started.md @@ -32,14 +32,7 @@ and returns a type that can be converted into `HttpResponse`: Filename: `src/main.rs` -```rust -extern crate actix_web; -use actix_web::{HttpRequest, App, server}; - -fn index(_req: HttpRequest) -> &'static str { - "Hello world!" -} -``` +{{< include-example example="getting-started" section="setup" >}} Next, create an `Application` instance and register the request handler with the application's `resource` on a particular *HTTP method* and *path* and @@ -48,16 +41,7 @@ for incoming connections. The server accepts a function that should return an `HttpHandler` instance. For simplicity `server::new` could be used, this function is shortcut for `HttpServer::new`: -```rust -fn main() { - server::new(|| { - App::new() - .resource("/", |r| r.f(index)) - }) - .bind("127.0.0.1:8088").unwrap() - .run(); -} -``` +{{< include-example example="getting-started" section="main" >}} That's it! Now, compile and run the program with `cargo run`. Head over to ``http://localhost:8088/`` to see the results. diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 2cb1e30..dcc7928 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,4 +1,5 @@ [workspace] members = [ "application", + "getting-started", ] diff --git a/examples/getting-started/Cargo.toml b/examples/getting-started/Cargo.toml new file mode 100644 index 0000000..b7b3d54 --- /dev/null +++ b/examples/getting-started/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "getting-started" +version = "0.1.0" + +[dependencies] +actix-web = "0.6" diff --git a/examples/getting-started/src/main.rs b/examples/getting-started/src/main.rs new file mode 100644 index 0000000..7b96fad --- /dev/null +++ b/examples/getting-started/src/main.rs @@ -0,0 +1,18 @@ +// +extern crate actix_web; +use actix_web::{HttpRequest, App, server}; + +fn index(_req: HttpRequest) -> &'static str { + "Hello world!" +} +// +//
+fn main() { + server::new(|| { + App::new() + .resource("/", |r| r.f(index)) + }) + .bind("127.0.0.1:8088").unwrap() + .run(); +} +//