diff --git a/config.toml b/config.toml index 72274c9..7ee657c 100644 --- a/config.toml +++ b/config.toml @@ -17,5 +17,6 @@ baseURL = "https://actix.rs" [params] actixVersion = "0.9" actixWebVersion = "2.0" +actixRtVersion = "1.0" actixWebMinRustVersion = "1.39" actixMinRustVersion = "1.39" diff --git a/content/_index.md b/content/_index.md index 7e9a9a9..e9b2885 100644 --- a/content/_index.md +++ b/content/_index.md @@ -1,3 +1,3 @@ --- -title: Actix - Actor System and Web Framework for Rust +title: rust's powerful actor system and most fun web framework --- diff --git a/content/docs/getting-started.md b/content/docs/getting-started.md index 0ede4d0..aa7ffab 100644 --- a/content/docs/getting-started.md +++ b/content/docs/getting-started.md @@ -23,25 +23,26 @@ contains the following: ```ini [dependencies] actix-web = "{{< actix-version "actix-web" >}}" +actix-rt = "{{< actix-version "actix-rt" >}}" ``` In order to implement a web server, we first need to create a request handler. -A request handler is a function that accepts zero or more parameters that can be +A request handler is an async function that accepts zero or more parameters that can be extracted from a request (ie, `impl FromRequest`) and returns a type that can be converted into an `HttpResponse` (ie, `impl Responder`): {{< include-example example="getting-started" section="setup" >}} Next, create an `App` instance and register the request handler with the application's -`route` on a *path* and with a particular *HTTP method*. After that, the application +`route` on a _path_ and with a particular _HTTP method_. After that, the application instance can be used with `HttpServer` to listen for incoming connections. The server accepts a function that should return an application factory. {{< include-example example="getting-started" section="main" >}} 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. ### Using Attribute Macros to Define Routes diff --git a/examples/getting-started/Cargo.toml b/examples/getting-started/Cargo.toml index fee4ef7..2f5db24 100644 --- a/examples/getting-started/Cargo.toml +++ b/examples/getting-started/Cargo.toml @@ -6,4 +6,4 @@ workspace = "../" [dependencies] actix-web = "2.0" -actix-rt = "1.0" +actix-rt = "1.0.0" diff --git a/layouts/index.html b/layouts/index.html index b2f0d4f..307f635 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -4,7 +4,8 @@
-

rust's powerful actor system and most fun web framework

+

rust's powerful actor system and most fun web framework +

@@ -30,32 +31,33 @@

Easily create your own libraries that any Actix application can use.

-

- - Blazingly Fast -

-

Actix is blazingly fast. Don't take our word for it -- see for yourself!

+

+ + Blazingly Fast +

+

Actix is blazingly fast. Don't take our word for it -- see for yourself!

+ - -
-
- {{ highlight `use actix_web::{web, App, HttpRequest, HttpServer, Responder}; +
+
+ {{ highlight `use actix_web::{web, App, HttpRequest, HttpServer, Responder}; -fn greet(req: HttpRequest) -> impl Responder { +async fn greet(req: HttpRequest) -> impl Responder { let name = req.match_info().get("name").unwrap_or("World"); format!("Hello {}!", &name) } -fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .route("/", web::get().to(greet)) .route("/{name}", web::get().to(greet)) }) - .bind("127.0.0.1:8000") - .expect("Can not bind to port 8000") + .bind("127.0.0.1:8000")? .run() - .unwrap(); + .await }` "rust" "" }}
@@ -66,7 +68,7 @@ fn main() {

Flexible Responders

Handler functions in actix can return a wide range of objects that - implement the Responder trait. This makes it a breeze + implement the Responder trait. This makes it a breeze to return consistent responses from your APIs.

{{ highlight `#[derive(Serialize)] @@ -74,11 +76,11 @@ struct Measurement { temperature: f32, } -fn hello_world() -> impl Responder { +async fn hello_world() -> impl Responder { "Hello World!" } -fn current_temperature() -> impl Responder { +async fn current_temperature() -> impl Responder { web::Json(Measurement { temperature: 42.3 }) }` "rust" "" }}
@@ -99,7 +101,7 @@ struct Event { tags: Vec, } -fn capture_event(evt: web::Json) -> impl Responder { +async fn capture_event(evt: web::Json) -> impl Responder { let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags); format!("got event {}", new_event.id.unwrap()) }` "rust" "" }} @@ -107,7 +109,7 @@ fn capture_event(evt: web::Json) -> impl Responder {

Easy Form Handling

- Handling multipart/urlencoded form data is easy. Just define + Handling multipart/urlencoded form data is easy. Just define a structure that can be deserialized and actix will handle the rest.

@@ -117,7 +119,7 @@ struct Register { country: String, } -fn register(form: web::Form) -> impl Responder { +async fn register(form: web::Form) -> impl Responder { format!("Hello {} from {}!", form.username, form.country) }` "rust" "" }}
@@ -125,22 +127,21 @@ fn register(form: web::Form) -> impl Responder {

Request Routing

An actix app comes with a URL routing system that lets you match on - URLs and invoke individual handlers. For extra flexibility, scopes + URLs and invoke individual handlers. For extra flexibility, scopes can be used.

- {{ highlight `fn index(_req: HttpRequest) -> impl Responder { + {{ highlight `async fn index(_req: HttpRequest) -> impl Responder { "Hello from the index page!" } -fn hello(path: web::Path) -> impl Responder { +async fn hello(path: web::Path) -> impl Responder { format!("Hello {}!", &path) } -fn main() { - App::new() +let app = App::new() .route("/", web::get().to(index)) .route("/{name}", web::get().to(hello)); -}` "rust" "" }} +` "rust" "" }}
@@ -155,4 +156,4 @@ fn main() {
-{{ partial "footer" . }} +{{ partial "footer" . }} \ No newline at end of file diff --git a/layouts/shortcodes/actix-version.html b/layouts/shortcodes/actix-version.html index 28efc3c..8b8b1df 100644 --- a/layouts/shortcodes/actix-version.html +++ b/layouts/shortcodes/actix-version.html @@ -2,4 +2,6 @@ {{- .Page.Site.Params.actixVersion -}} {{- else if eq (.Get 0) "actix-web" -}} {{- .Page.Site.Params.actixWebVersion -}} -{{- end -}} +{{- else if eq (.Get 0) "actix-rt" -}} + {{- .Page.Site.Params.actixRtVersion -}} +{{- end -}} \ No newline at end of file