1
0
mirror of https://github.com/actix/actix-website synced 2024-12-12 16:00:23 +01:00
actix-website/layouts/index.html
2022-02-26 04:38:18 +00:00

176 lines
5.9 KiB
HTML

{{ partial "header" . }}
<div id="act-home">
<div class="jumbotron">
<div class="actix-jumbotron">
<img src="/img/logo-large.png" class="align-middle actix-logo" alt="">
<p class="lead">
A powerful, pragmatic, and extremely fast web framework for Rust
</p>
<a href="/docs/getting-started/" class="btn btn-secondary actix-jumbotron-install">
Get Started
</a>
</div>
</div>
<div class="container actix-home">
<div class="row">
<div class="col-md-4">
<div class="actix-features">
<h2>
<i class="fa fa-fw fa-shield" aria-hidden="true"></i>
Type Safe
</h2>
<p>Forget about stringly typed objects, from request to response, everything has types.</p>
<h2>
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
Feature Rich
</h2>
<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 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 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::{get, web, App, HttpServer, Responder};
#[get("/{name}")]
async fn greet_person(name: web::Path<String>) -> impl Responder {
format!("Hello {name}!")
}
#[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(|| async { "Hello World!" }))
.service(greet_person)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
` "rust" "" }}
</div>
</div>
</div>
<div class="actix-showcase">
<div class="col-md-9">
<div class="actix-feature" id="responders">
<h2>Flexible Responders</h2>
<p>
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 `async fn current_temperature() -> impl Responder {
web::Json(json!({ "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 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 EventForm {
kind: String,
tags: Vec<String>,
}
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 Web will handle the rest.
</p>
{{ highlight `use actix_web::web::{Either, Json, Form};
#[derive(Deserialize)]
struct Register {
username: String,
country: String,
}
// 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>
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 {
"Hello from the index page!"
}
async fn hello(path: web::Path<String>) -> impl Responder {
format!("Hello {}!", &path)
}
let app = App::new()
.service(index)
.route("/{name}", web::get().to(hello));
` "rust" "" }}
</div>
</div>
<div class="col-md-3 actix-feature-selectors">
<ul>
<li class="actix-feature-selector"><a href="#responders">flexible responders</a></li>
<li class="actix-feature-selector"><a href="#extractors">powerful extractors</a></li>
<li class="actix-feature-selector"><a href="#forms">easy form handling</a></li>
<li class="actix-feature-selector"><a href="#routing">request routing</a></li>
</ul>
</div>
</div>
</div>
</div>
{{ partial "footer" . }}