1
0
mirror of https://github.com/actix/actix-website synced 2024-11-28 02:22:57 +01:00
actix-website/layouts/index.html

165 lines
5.3 KiB
HTML
Raw Normal View History

2018-05-22 23:15:08 +02:00
{{ partial "header" . }}
2018-06-23 05:36:37 +02:00
<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">
2020-09-12 17:21:54 +02:00
A powerful, pragmatic, and extremely fast web framework for Rust
2019-12-29 14:57:11 +01:00
</p>
2020-09-13 04:18:50 +02:00
<a href="/docs/getting-started/" class="btn btn-secondary actix-jumbotron-install">
Get Started
</a>
2018-06-23 05:36:37 +02:00
</div>
2018-05-22 23:15:08 +02:00
</div>
2018-06-23 05:36:37 +02:00
<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>
2018-05-22 23:15:08 +02:00
2018-06-23 05:36:37 +02:00
<h2>
<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>
2018-05-22 23:15:08 +02:00
2018-06-23 05:36:37 +02:00
<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>
2018-05-22 23:15:08 +02:00
2019-12-29 14:57:11 +01:00
<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
2020-09-12 17:21:54 +02:00
href="https://www.techempower.com/benchmarks/#section=data-r19">see for yourself!</a></p>
2019-12-29 14:57:11 +01:00
</div>
2018-05-22 23:15:08 +02:00
</div>
2019-12-29 14:57:11 +01:00
<div class="col-md-8">
<div class="actix-content">
{{ highlight `use actix_web::{web, App, HttpRequest, HttpServer, Responder};
2018-05-22 23:15:08 +02:00
2019-12-29 14:57:11 +01:00
async fn greet(req: HttpRequest) -> impl Responder {
2019-06-12 10:51:45 +02:00
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
2018-05-22 23:15:08 +02:00
}
2020-09-12 17:21:54 +02:00
#[actix_web::main]
2019-12-29 14:57:11 +01:00
async fn main() -> std::io::Result<()> {
2019-06-12 10:51:45 +02:00
HttpServer::new(|| {
2018-05-22 23:15:08 +02:00
App::new()
2019-06-19 20:24:31 +02:00
.route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
2018-05-22 23:15:08 +02:00
})
.bind(("127.0.0.1", 8080))?
2019-06-12 10:51:45 +02:00
.run()
2019-12-29 14:57:11 +01:00
.await
2018-05-22 23:15:08 +02:00
}` "rust" "" }}
2018-06-23 05:36:37 +02:00
</div>
2018-05-22 23:15:08 +02:00
</div>
</div>
2018-06-23 05:36:37 +02:00
<div class="actix-showcase">
<div class="col-md-9">
<div class="actix-feature" id="responders">
<h2>Flexible Responders</h2>
<p>
Handler functions in actix can return a wide range of objects that
2019-12-29 14:57:11 +01:00
implement the <code>Responder</code> trait. This makes it a breeze
2018-06-23 05:36:37 +02:00
to return consistent responses from your APIs.
</p>
{{ highlight `#[derive(Serialize)]
2018-05-23 20:15:15 +02:00
struct Measurement {
temperature: f32,
}
2019-12-29 14:57:11 +01:00
async fn hello_world() -> impl Responder {
2018-05-23 20:15:15 +02:00
"Hello World!"
}
2019-12-29 14:57:11 +01:00
async fn current_temperature() -> impl Responder {
web::Json(Measurement { temperature: 42.3 })
2018-05-23 20:15:15 +02:00
}` "rust" "" }}
2018-06-23 05:36:37 +02:00
</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.
</p>
{{ highlight `#[derive(Deserialize, Serialize)]
2018-05-23 20:15:15 +02:00
struct Event {
id: Option<i32>,
2018-05-23 20:15:15 +02:00
timestamp: f64,
kind: String,
tags: Vec<String>,
}
2019-06-19 20:24:31 +02:00
2019-12-29 14:57:11 +01:00
async fn capture_event(evt: web::Json<Event>) -> impl Responder {
2019-06-19 20:24:31 +02:00
let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags);
format!("got event {}", new_event.id.unwrap())
2018-05-23 20:15:15 +02:00
}` "rust" "" }}
2018-06-23 05:36:37 +02:00
</div>
<div class="actix-feature" id="forms">
<h2>Easy Form Handling</h2>
<p>
2019-12-29 14:57:11 +01:00
Handling multipart/urlencoded form data is easy. Just define
2018-06-23 05:36:37 +02:00
a structure that can be deserialized and actix will handle
the rest.
</p>
{{ highlight `#[derive(Deserialize)]
2018-05-23 20:15:15 +02:00
struct Register {
username: String,
country: String,
}
2019-12-29 14:57:11 +01:00
async fn register(form: web::Form<Register>) -> impl Responder {
2019-06-19 20:24:31 +02:00
format!("Hello {} from {}!", form.username, form.country)
2018-05-26 14:27:55 +02:00
}` "rust" "" }}
2018-06-23 05:36:37 +02:00
</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
2019-12-29 14:57:11 +01:00
URLs and invoke individual handlers. For extra flexibility, scopes
2018-06-23 05:36:37 +02:00
can be used.
</p>
2020-09-12 17:21:54 +02:00
{{ highlight `#[get("/")]
async fn index(_req: HttpRequest) -> impl Responder {
"Hello from the index page!"
2018-05-26 14:27:55 +02:00
}
2019-12-29 14:57:11 +01:00
async fn hello(path: web::Path<String>) -> impl Responder {
format!("Hello {}!", &path)
2018-05-26 14:27:55 +02:00
}
2019-12-29 14:57:11 +01:00
let app = App::new()
2020-09-12 17:21:54 +02:00
.service(index)
.route("/{name}", web::get().to(hello));
2019-12-29 14:57:11 +01:00
` "rust" "" }}
2018-06-23 05:36:37 +02:00
</div>
</div>
<div class="col-md-3 actix-feature-selectors">
<ul>
<li class="actix-feature-selector"><a href="#responders">flexible responders</label>
<li class="actix-feature-selector"><a href="#extractors">powerful extractors</label>
<li class="actix-feature-selector"><a href="#forms">easy form handling</label>
<li class="actix-feature-selector"><a href="#routing">request routing</label>
</ul>
2018-05-23 20:15:15 +02:00
</div>
</div>
</div>
2018-05-22 23:15:08 +02:00
</div>
{{ partial "footer" . }}