1
0
mirror of https://github.com/actix/actix-website synced 2024-11-24 00:41:07 +01:00

Document actix-web-codegen

This fixes #105
This commit is contained in:
Sven-Hendrik Haase 2019-08-05 18:32:00 +02:00
parent cf666d228b
commit 553fe281fc
2 changed files with 28 additions and 0 deletions

View File

@ -43,6 +43,24 @@ accepts a function that should return an application factory.
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.
### Alternative syntax
You might prefer the alternative syntax provided by [actix-web-codegen] which
allows you to specify the routes above your functions like so:
{{< include-example example="getting-started" section="alternative">}}
You can then declare this function using `service()`:
```rust
App::new()
.service(index3)
```
For consistency reasons, this documentation only uses the regular syntax shown at the
beginning of this page. However, if you prefer this syntax you should feel free to
use it any time you declare a route as it's only syntactic sugar.
### Auto-reloading ### Auto-reloading
If you want, you can have an automatically reloading server during development If you want, you can have an automatically reloading server during development
@ -50,4 +68,5 @@ that recompiles on demand. This isn't necessary, but it makes rapid prototyping
more convenient as you can see changes instantly upon saving. more convenient as you can see changes instantly upon saving.
To see how this can be accomplished, have a look at the [autoreload pattern][autoload]. To see how this can be accomplished, have a look at the [autoreload pattern][autoload].
[actix-web-codegen]: https://docs.rs/actix-web-codegen/0.1.2/actix_web_codegen/
[autoload]: ../autoreload/ [autoload]: ../autoreload/

View File

@ -10,6 +10,15 @@ fn index2() -> impl Responder {
} }
// </setup> // </setup>
// <alternative>
use actix_web::get;
#[get("/alternative")]
fn index3() -> impl Responder {
HttpResponse::Ok().body("Sweet syntax!")
}
// </alternative>
// <main> // <main>
fn main() { fn main() {
HttpServer::new(|| { HttpServer::new(|| {