mirror of
https://github.com/actix/actix-website
synced 2025-02-24 21:13:20 +01:00
Fix PR comments
This commit is contained in:
parent
553fe281fc
commit
04bca7bf82
@ -43,24 +43,26 @@ 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
|
### Using Attribute Macros to Define Routes
|
||||||
|
|
||||||
You might prefer the alternative syntax provided by [actix-web-codegen] which
|
Alternatively, you can define routes using macro attributes which
|
||||||
allows you to specify the routes above your functions like so:
|
allows you to specify the routes above your functions like so:
|
||||||
|
|
||||||
{{< include-example example="getting-started" section="alternative">}}
|
{{< include-example example="getting-started" section="macro-attributes">}}
|
||||||
|
|
||||||
You can then declare this function using `service()`:
|
You can then register the route using `service()`:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
App::new()
|
App::new()
|
||||||
.service(index3)
|
.service(index3)
|
||||||
```
|
```
|
||||||
|
|
||||||
For consistency reasons, this documentation only uses the regular syntax shown at the
|
For consistency reasons, this documentation only uses the explicit syntax shown at the
|
||||||
beginning of this page. However, if you prefer this syntax you should feel free to
|
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.
|
use it any time you declare a route as it's only syntactic sugar.
|
||||||
|
|
||||||
|
To learn more, see [actix-web-codegen].
|
||||||
|
|
||||||
### 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
|
||||||
|
@ -10,14 +10,14 @@ fn index2() -> impl Responder {
|
|||||||
}
|
}
|
||||||
// </setup>
|
// </setup>
|
||||||
|
|
||||||
// <alternative>
|
// <macro-attributes>
|
||||||
use actix_web::get;
|
use actix_web::get;
|
||||||
|
|
||||||
#[get("/alternative")]
|
#[get("/hello")]
|
||||||
fn index3() -> impl Responder {
|
fn index3() -> impl Responder {
|
||||||
HttpResponse::Ok().body("Sweet syntax!")
|
HttpResponse::Ok().body("Hey there!")
|
||||||
}
|
}
|
||||||
// </alternative>
|
// </macro-attributes>
|
||||||
|
|
||||||
// <main>
|
// <main>
|
||||||
fn main() {
|
fn main() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user