From 6b4fe2882b31fbb7dfe3640878c8deb898aa8b41 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 26 Feb 2022 04:38:18 +0000 Subject: [PATCH] update homepage --- .gitignore | 1 + config.toml | 10 +++--- layouts/index.html | 89 ++++++++++++++++++++++++++-------------------- 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index f52679b..a80786c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Cargo.lock build/ target/ .DS_Store +/.hugo_build.lock diff --git a/config.toml b/config.toml index 4bc6f2a..e6e1061 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,6 @@ title = "actix" canonifyURLs = true -googleAnalytics = "UA-110322332-1" +googleAnalytics = "" pygmentsUseClasses = true pygmentsCodeFences = true defaultContentLanguageInSubdir = false @@ -16,7 +16,7 @@ weight = 1 [params] actixVersion = "0.10" -actixWebVersion = "3" -actixRtVersion = "1.1" -actixWebMinRustVersion = "1.42" -actixMinRustVersion = "1.42" +actixWebVersion = "4" +actixRtVersion = "2" +actixWebMinRustVersion = "1.54" +actixMinRustVersion = "1.54" diff --git a/layouts/index.html b/layouts/index.html index 4d08b29..7856907 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -27,42 +27,46 @@ Feature Rich -

Actix provides a lot of features out of box. HTTP/2, logging, etc.

+

+ Out of the box logging, body compression, static file serving, TLS, HTTP/2, and + much more. +

Extensible

-

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

+

Easily create and share reusable components for any Actix Web application.

Blazingly Fast

-

Actix is blazingly fast. Don't take our word for it -- Actix Web 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::{get, web, App, HttpServer, Responder}; -async fn greet(req: HttpRequest) -> impl Responder { - let name = req.match_info().get("name").unwrap_or("World"); - format!("Hello {}!", &name) +#[get("/{name}")] +async fn greet_person(name: web::Path) -> impl Responder { + format!("Hello {name}!") } -#[actix_web::main] +#[actix_web::main] // or #[tokio::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() - .route("/", web::get().to(greet)) - .route("/{name}", web::get().to(greet)) + .route("/", web::get().to(|| async { "Hello World!" })) + .service(greet_person) }) .bind(("127.0.0.1", 8080))? .run() .await -}` "rust" "" }} +} +` "rust" "" }}
@@ -71,68 +75,75 @@ async fn main() -> std::io::Result<()> {

Flexible Responders

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

- {{ highlight `#[derive(Serialize)] -struct Measurement { - temperature: f32, + {{ highlight `async fn current_temperature() -> impl Responder { + web::Json(json!({ "temperature": 42.3 })) } -async fn hello_world() -> impl Responder { - "Hello World!" -} - -async fn current_temperature() -> impl Responder { - web::Json(Measurement { temperature: 42.3 }) +async fn hello_world() -> actix_web::Result { + Ok("Hello World!") }` "rust" "" }}

Powerful Extractors

- Actix comes with a powerful extractor system that extracts data - from the incoming HTTP request and passes it to your view functions. - Not only does this make for a convenient API but it also means that - your view functions can be synchronous code and still benefit - from asynchronous IO handling. + Actix Web comes with a powerful extractor system that extracts parts of the incoming + HTTP request and passes it to your handler functions. +

+

+ A handler function can receive up to 12 arguments that implement the + FromRequest trait, in any order, and Actix Web will automatically extract + them from the request and provide them. It feels like magic!

{{ highlight `#[derive(Deserialize, Serialize)] -struct Event { - id: Option, - timestamp: f64, +struct EventForm { kind: String, tags: Vec, } -async fn capture_event(evt: web::Json) -> impl Responder { - let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags); +async fn capture_event(evt: web::Json, db: web::Data) -> impl Responder { + let new_event = db.store(&evt.kind, &evt.tags).await; format!("got event {}", new_event.id.unwrap()) }` "rust" "" }}

Easy Form Handling

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

- {{ highlight `#[derive(Deserialize)] + {{ highlight `use actix_web::web::{Either, Json, Form}; + +#[derive(Deserialize)] struct Register { username: String, country: String, } -async fn register(form: web::Form) -> impl Responder { +// register form is JSON +async fn register(form: web::Json) -> impl Responder { format!("Hello {} from {}!", form.username, form.country) +} + +// register form can be either JSON or URL-encoded +async fn register(form: Either, Form>) -> impl Responder { + let Register { username, country } = form.into_inner(); + format!("Hello {username} from {country}!") }` "rust" "" }}

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 - can be used. + The built-in Actix Web request router can be used with or without macros attached to + handlers, and always provides flexible and composable methods of creating routing + tables. +

+

+ Includes support for matching dynamic path segments, path prefix groups, and custom + routing guards which let you define your own rules.

{{ highlight `#[get("/")] async fn index(_req: HttpRequest) -> impl Responder {