From 553fe281fca7a2da6991bcb396ebd9c4aec57a13 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Mon, 5 Aug 2019 18:32:00 +0200 Subject: [PATCH 1/3] Document actix-web-codegen This fixes #105 --- content/docs/getting-started.md | 19 +++++++++++++++++++ examples/getting-started/src/main.rs | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/content/docs/getting-started.md b/content/docs/getting-started.md index 21a6c44..ba06e7e 100644 --- a/content/docs/getting-started.md +++ b/content/docs/getting-started.md @@ -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`. 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 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. 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/ diff --git a/examples/getting-started/src/main.rs b/examples/getting-started/src/main.rs index 4b2cfa6..28fd7c2 100644 --- a/examples/getting-started/src/main.rs +++ b/examples/getting-started/src/main.rs @@ -10,6 +10,15 @@ fn index2() -> impl Responder { } // +// +use actix_web::get; + +#[get("/alternative")] +fn index3() -> impl Responder { + HttpResponse::Ok().body("Sweet syntax!") +} +// + //
fn main() { HttpServer::new(|| { From 04bca7bf82b08079754fe259c9ec4a7a3bb6267e Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Tue, 6 Aug 2019 01:30:50 +0200 Subject: [PATCH 2/3] Fix PR comments --- content/docs/getting-started.md | 12 +++++++----- examples/getting-started/src/main.rs | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/content/docs/getting-started.md b/content/docs/getting-started.md index ba06e7e..6f2efd7 100644 --- a/content/docs/getting-started.md +++ b/content/docs/getting-started.md @@ -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`. 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: -{{< 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 App::new() .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 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 diff --git a/examples/getting-started/src/main.rs b/examples/getting-started/src/main.rs index 28fd7c2..8208bae 100644 --- a/examples/getting-started/src/main.rs +++ b/examples/getting-started/src/main.rs @@ -10,14 +10,14 @@ fn index2() -> impl Responder { } // -// +// use actix_web::get; -#[get("/alternative")] +#[get("/hello")] fn index3() -> impl Responder { - HttpResponse::Ok().body("Sweet syntax!") + HttpResponse::Ok().body("Hey there!") } -// +// //
fn main() { From 421730743556d3fb2ef30bad67d7381b033b8b09 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Tue, 6 Aug 2019 09:52:22 +0200 Subject: [PATCH 3/3] allows -> allow --- content/docs/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/getting-started.md b/content/docs/getting-started.md index 6f2efd7..6515cfc 100644 --- a/content/docs/getting-started.md +++ b/content/docs/getting-started.md @@ -46,7 +46,7 @@ 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: +allow you to specify the routes above your functions like so: {{< include-example example="getting-started" section="macro-attributes">}}