1
0
mirror of https://github.com/actix/actix-website synced 2024-11-27 18:12:57 +01:00

update homepage

This commit is contained in:
Rob Ede 2022-02-26 04:38:18 +00:00
parent 81dfe300a2
commit 6b4fe2882b
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 56 additions and 44 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ Cargo.lock
build/ build/
target/ target/
.DS_Store .DS_Store
/.hugo_build.lock

View File

@ -1,6 +1,6 @@
title = "actix" title = "actix"
canonifyURLs = true canonifyURLs = true
googleAnalytics = "UA-110322332-1" googleAnalytics = ""
pygmentsUseClasses = true pygmentsUseClasses = true
pygmentsCodeFences = true pygmentsCodeFences = true
defaultContentLanguageInSubdir = false defaultContentLanguageInSubdir = false
@ -16,7 +16,7 @@ weight = 1
[params] [params]
actixVersion = "0.10" actixVersion = "0.10"
actixWebVersion = "3" actixWebVersion = "4"
actixRtVersion = "1.1" actixRtVersion = "2"
actixWebMinRustVersion = "1.42" actixWebMinRustVersion = "1.54"
actixMinRustVersion = "1.42" actixMinRustVersion = "1.54"

View File

@ -27,42 +27,46 @@
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i> <i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
Feature Rich Feature Rich
</h2> </h2>
<p>Actix provides a lot of features out of box. HTTP/2, logging, etc.</p> <p>
Out of the box logging, body compression, static file serving, TLS, HTTP/2, and
much more.
</p>
<h2> <h2>
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i> <i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
Extensible Extensible
</h2> </h2>
<p>Easily create your own libraries that any Actix application can use.</p> <p>Easily create and share reusable components for any Actix Web application.</p>
<h2> <h2>
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i> <i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
Blazingly Fast Blazingly Fast
</h2> </h2>
<p>Actix is blazingly fast. Don't take our word for it -- <a <p>Actix Web is blazingly fast. Don't take our word for it -- <a
href="https://www.techempower.com/benchmarks/#section=data-r20&hw=ph&test=fortune">see for yourself!</a></p> href="https://www.techempower.com/benchmarks/#section=data-r20&hw=ph&test=fortune">see for yourself!</a></p>
</div> </div>
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
<div class="actix-content"> <div class="actix-content">
{{ 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 { #[get("/{name}")]
let name = req.match_info().get("name").unwrap_or("World"); async fn greet_person(name: web::Path<String>) -> impl Responder {
format!("Hello {}!", &name) format!("Hello {name}!")
} }
#[actix_web::main] #[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
HttpServer::new(|| { HttpServer::new(|| {
App::new() App::new()
.route("/", web::get().to(greet)) .route("/", web::get().to(|| async { "Hello World!" }))
.route("/{name}", web::get().to(greet)) .service(greet_person)
}) })
.bind(("127.0.0.1", 8080))? .bind(("127.0.0.1", 8080))?
.run() .run()
.await .await
}` "rust" "" }} }
` "rust" "" }}
</div> </div>
</div> </div>
</div> </div>
@ -71,68 +75,75 @@ async fn main() -> std::io::Result<()> {
<div class="actix-feature" id="responders"> <div class="actix-feature" id="responders">
<h2>Flexible Responders</h2> <h2>Flexible Responders</h2>
<p> <p>
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 <code>Responder</code> trait. This makes it a breeze implement the <code>Responder</code> trait. This makes it a breeze
to return consistent responses from your APIs. to return consistent responses from your APIs.
</p> </p>
{{ highlight `#[derive(Serialize)] {{ highlight `async fn current_temperature() -> impl Responder {
struct Measurement { web::Json(json!({ "temperature": 42.3 }))
temperature: f32,
} }
async fn hello_world() -> impl Responder { async fn hello_world() -> actix_web::Result<impl Responder> {
"Hello World!" Ok("Hello World!")
}
async fn current_temperature() -> impl Responder {
web::Json(Measurement { temperature: 42.3 })
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div class="actix-feature" id="extractors"> <div class="actix-feature" id="extractors">
<h2>Powerful Extractors</h2> <h2>Powerful Extractors</h2>
<p> <p>
Actix comes with a powerful extractor system that extracts data Actix Web comes with a powerful extractor system that extracts parts of the incoming
from the incoming HTTP request and passes it to your view functions. HTTP request and passes it to your handler functions.
Not only does this make for a convenient API but it also means that </p>
your view functions can be synchronous code and still benefit <p>
from asynchronous IO handling. A handler function can receive up to 12 arguments that implement the
<code>FromRequest</code> trait, in any order, and Actix Web will automatically extract
them from the request and provide them. It feels like magic!
</p> </p>
{{ highlight `#[derive(Deserialize, Serialize)] {{ highlight `#[derive(Deserialize, Serialize)]
struct Event { struct EventForm {
id: Option<i32>,
timestamp: f64,
kind: String, kind: String,
tags: Vec<String>, tags: Vec<String>,
} }
async fn capture_event(evt: web::Json<Event>) -> impl Responder { async fn capture_event(evt: web::Json<EventForm>, db: web::Data<Db>) -> impl Responder {
let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags); let new_event = db.store(&evt.kind, &evt.tags).await;
format!("got event {}", new_event.id.unwrap()) format!("got event {}", new_event.id.unwrap())
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div class="actix-feature" id="forms"> <div class="actix-feature" id="forms">
<h2>Easy Form Handling</h2> <h2>Easy Form Handling</h2>
<p> <p>
Handling multipart/urlencoded form data is easy. Just define Handling multipart/urlencoded form data is easy. Just define a structure that can be
a structure that can be deserialized and actix will handle deserialized and Actix Web will handle the rest.
the rest.
</p> </p>
{{ highlight `#[derive(Deserialize)] {{ highlight `use actix_web::web::{Either, Json, Form};
#[derive(Deserialize)]
struct Register { struct Register {
username: String, username: String,
country: String, country: String,
} }
async fn register(form: web::Form<Register>) -> impl Responder { // register form is JSON
async fn register(form: web::Json<Register>) -> impl Responder {
format!("Hello {} from {}!", form.username, form.country) format!("Hello {} from {}!", form.username, form.country)
}
// register form can be either JSON or URL-encoded
async fn register(form: Either<Json<Register>, Form<Register>>) -> impl Responder {
let Register { username, country } = form.into_inner();
format!("Hello {username} from {country}!")
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div class="actix-feature" id="routing"> <div class="actix-feature" id="routing">
<h2>Request Routing</h2> <h2>Request Routing</h2>
<p> <p>
An actix app comes with a URL routing system that lets you match on The built-in Actix Web request router can be used with or without macros attached to
URLs and invoke individual handlers. For extra flexibility, scopes handlers, and always provides flexible and composable methods of creating routing
can be used. tables.
</p>
<p>
Includes support for matching dynamic path segments, path prefix groups, and custom
routing guards which let you define your own rules.
</p> </p>
{{ highlight `#[get("/")] {{ highlight `#[get("/")]
async fn index(_req: HttpRequest) -> impl Responder { async fn index(_req: HttpRequest) -> impl Responder {