Expand description
Actix web is a small, pragmatic, and extremely fast web framework for Rust.
use actix_web::{server, App, Path, Responder};
fn index(info: Path<(String, u32)>) -> impl Responder {
format!("Hello {}! id:{}", info.0, info.1)
}
fn main() {
server::new(|| {
App::new().resource("/{name}/{id}/index.html", |r| r.with(index))
}).bind("127.0.0.1:8080")
.unwrap()
.run();
}
Documentation & community resources
Besides the API documentation (which you are currently looking at!), several other resources are available:
To get started navigating the API documentation you may want to consider looking at the following pages:
-
App: This struct represents an actix-web application and is used to configure routes and other common settings.
-
HttpServer: This struct represents an HTTP server instance and is used to instantiate and configure servers.
-
HttpRequest and HttpResponse: These structs represent HTTP requests and responses and expose various methods for inspecting, creating and otherwise utilizing them.
Features
- Supported HTTP/1.x and HTTP/2.0 protocols
- Streaming and pipelining
- Keep-alive and slow requests handling
WebSockets
server/client- Transparent content compression/decompression (br, gzip, deflate)
- Configurable request routing
- Graceful server shutdown
- Multipart streams
- SSL support with OpenSSL or
native-tls
- Middlewares (
Logger
,Session
,CORS
,CSRF
,DefaultHeaders
) - Built on top of Actix actor framework
- Supported Rust version: 1.26 or later
Package feature
tls
- enables ssl support vianative-tls
cratessl
- enables ssl support viaopenssl
crate, supportshttp/2
rust-tls
- enables ssl support viarustls
crate, supportshttp/2
uds
- enables support for making client requests via Unix Domain Sockets. Unix only. Not necessary for serving requests.session
- enables session support, includesring
crate as dependencybrotli
- enablesbrotli
compression support, requiresc
compilerflate2-c
- enablesgzip
,deflate
compression support, requiresc
compilerflate2-rust
- experimental rust based implementation forgzip
,deflate
compression.
Re-exports
Modules
Http client api
The
actix-web
prelude for library developersError and Result module
Static files support
Various HTTP related types
Middlewares
Multipart requests support
Route match predicates
Http server module
Various helpers for Actix applications to use during testing.
WebSocket
support for ActixMacros
Structs
Structure that follows the builder pattern for building application
instances.
A type map of request extensions.
Extract typed information from the request’s body.
Execution context for http actors
An HTTP Request
An HTTP Response
Json helper
Extract typed information from the request’s path. Information from the path is
URL decoded. Decoding of special characters can be disabled through
PathConfig
.Extract typed information from from the request’s query.
Request’s context
Resources scope
Access an application state
Enums
Represents various types of binary body.
Content-Length
header is set to length of the body.Represents various types of http message body.
Combines two different responder types into a single type
Traits
Convenience trait that converts
Future
object to a Boxed
futureTrait implemented by types that can be extracted from request.
Trait that implements general purpose operations on http messages
Trait implemented by types that generate responses for clients.
Type Definitions
Convenience type alias