Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document actix-web-codegen #108

Merged
merged 3 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions content/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,32 @@ 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
allows you to specify the routes above your functions like so:
svenstaro marked this conversation as resolved.
Show resolved Hide resolved

{{< 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
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/
9 changes: 9 additions & 0 deletions examples/getting-started/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down