1
0
mirror of https://github.com/actix/actix-website synced 2024-11-30 11: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/
target/
.DS_Store
/.hugo_build.lock

View File

@ -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"

View File

@ -27,42 +27,46 @@
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
Feature Rich
</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>
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
Extensible
</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>
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
Blazingly Fast
</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>
</div>
</div>
<div class="col-md-8">
<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 {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
#[get("/{name}")]
async fn greet_person(name: web::Path<String>) -> 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" "" }}
</div>
</div>
</div>
@ -71,68 +75,75 @@ async fn main() -> std::io::Result<()> {
<div class="actix-feature" id="responders">
<h2>Flexible Responders</h2>
<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
to return consistent responses from your APIs.
</p>
{{ 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<impl Responder> {
Ok("Hello World!")
}` "rust" "" }}
</div>
<div class="actix-feature" id="extractors">
<h2>Powerful Extractors</h2>
<p>
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.
</p>
<p>
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>
{{ highlight `#[derive(Deserialize, Serialize)]
struct Event {
id: Option<i32>,
timestamp: f64,
struct EventForm {
kind: String,
tags: Vec<String>,
}
async fn capture_event(evt: web::Json<Event>) -> impl Responder {
let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags);
async fn capture_event(evt: web::Json<EventForm>, db: web::Data<Db>) -> impl Responder {
let new_event = db.store(&evt.kind, &evt.tags).await;
format!("got event {}", new_event.id.unwrap())
}` "rust" "" }}
</div>
<div class="actix-feature" id="forms">
<h2>Easy Form Handling</h2>
<p>
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.
</p>
{{ 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<Register>) -> impl Responder {
// register form is JSON
async fn register(form: web::Json<Register>) -> impl Responder {
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" "" }}
</div>
<div class="actix-feature" id="routing">
<h2>Request Routing</h2>
<p>
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.
</p>
<p>
Includes support for matching dynamic path segments, path prefix groups, and custom
routing guards which let you define your own rules.
</p>
{{ highlight `#[get("/")]
async fn index(_req: HttpRequest) -> impl Responder {