mirror of
https://github.com/actix/actix-website
synced 2025-02-02 12:19:04 +01:00
Test getting-started example
This commit is contained in:
parent
b7025c029f
commit
ab91b27c13
@ -32,14 +32,7 @@ and returns a type that can be converted into `HttpResponse`:
|
|||||||
|
|
||||||
Filename: `src/main.rs`
|
Filename: `src/main.rs`
|
||||||
|
|
||||||
```rust
|
{{< include-example example="getting-started" section="setup" >}}
|
||||||
extern crate actix_web;
|
|
||||||
use actix_web::{HttpRequest, App, server};
|
|
||||||
|
|
||||||
fn index(_req: HttpRequest) -> &'static str {
|
|
||||||
"Hello world!"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Next, create an `Application` instance and register the request handler with
|
Next, create an `Application` instance and register the request handler with
|
||||||
the application's `resource` on a particular *HTTP method* and *path* and
|
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
|
`HttpHandler` instance. For simplicity `server::new` could be used, this
|
||||||
function is shortcut for `HttpServer::new`:
|
function is shortcut for `HttpServer::new`:
|
||||||
|
|
||||||
```rust
|
{{< include-example example="getting-started" section="main" >}}
|
||||||
fn main() {
|
|
||||||
server::new(|| {
|
|
||||||
App::new()
|
|
||||||
.resource("/", |r| r.f(index))
|
|
||||||
})
|
|
||||||
.bind("127.0.0.1:8088").unwrap()
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
That's it! Now, compile and run the program with `cargo run`.
|
That's it! Now, compile and run the program with `cargo run`.
|
||||||
Head over to ``http://localhost:8088/`` to see the results.
|
Head over to ``http://localhost:8088/`` to see the results.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"application",
|
"application",
|
||||||
|
"getting-started",
|
||||||
]
|
]
|
||||||
|
6
examples/getting-started/Cargo.toml
Normal file
6
examples/getting-started/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "getting-started"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
actix-web = "0.6"
|
18
examples/getting-started/src/main.rs
Normal file
18
examples/getting-started/src/main.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// <setup>
|
||||||
|
extern crate actix_web;
|
||||||
|
use actix_web::{HttpRequest, App, server};
|
||||||
|
|
||||||
|
fn index(_req: HttpRequest) -> &'static str {
|
||||||
|
"Hello world!"
|
||||||
|
}
|
||||||
|
// </setup>
|
||||||
|
// <main>
|
||||||
|
fn main() {
|
||||||
|
server::new(|| {
|
||||||
|
App::new()
|
||||||
|
.resource("/", |r| r.f(index))
|
||||||
|
})
|
||||||
|
.bind("127.0.0.1:8088").unwrap()
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
// </main>
|
Loading…
x
Reference in New Issue
Block a user