mirror of
https://github.com/actix/actix-website
synced 2024-11-30 19:14:36 +01:00
Merge pull request #108 from actix/document-actix-web-codegen
Document actix-web-codegen
This commit is contained in:
commit
29d1d51cf1
@ -43,6 +43,26 @@ accepts a function that should return an application factory.
|
||||
That's it! Now, compile and run the program with `cargo run`.
|
||||
Head over to ``http://localhost:8088/`` to see the results.
|
||||
|
||||
### Using Attribute Macros to Define Routes
|
||||
|
||||
Alternatively, you can define routes using macro attributes which
|
||||
allow you to specify the routes above your functions like so:
|
||||
|
||||
{{< include-example example="getting-started" section="macro-attributes">}}
|
||||
|
||||
You can then register the route using `service()`:
|
||||
|
||||
```rust
|
||||
App::new()
|
||||
.service(index3)
|
||||
```
|
||||
|
||||
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
|
||||
use it any time you declare a route as it's only syntactic sugar.
|
||||
|
||||
To learn more, see [actix-web-codegen].
|
||||
|
||||
### Auto-reloading
|
||||
|
||||
If you want, you can have an automatically reloading server during development
|
||||
@ -50,4 +70,5 @@ that recompiles on demand. This isn't necessary, but it makes rapid prototyping
|
||||
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].
|
||||
|
||||
[actix-web-codegen]: https://docs.rs/actix-web-codegen/0.1.2/actix_web_codegen/
|
||||
[autoload]: ../autoreload/
|
||||
|
@ -10,6 +10,15 @@ fn index2() -> impl Responder {
|
||||
}
|
||||
// </setup>
|
||||
|
||||
// <macro-attributes>
|
||||
use actix_web::get;
|
||||
|
||||
#[get("/hello")]
|
||||
fn index3() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hey there!")
|
||||
}
|
||||
// </macro-attributes>
|
||||
|
||||
// <main>
|
||||
fn main() {
|
||||
HttpServer::new(|| {
|
||||
|
Loading…
Reference in New Issue
Block a user