Actix Web
Overview
actix-web is a powerful, pragmatic, and extremely fast web framework for Rust. It supports HTTP/1.x and HTTP/2, streaming and pipelining, powerful request routing with optional macros, and comprehensive middleware. Built on Tokio and running on stable Rust, it ranks among the fastest web frameworks in TechEmpower benchmarks. Read this when building Rust HTTP APIs and services.
Official sources
Install / setup
cargo new hello-world
cd hello-world
# Cargo.toml — add the dependency (requires a recent stable Rust)
[dependencies]
actix-web = "4"
Core concepts
- App & HttpServer: an
App registers routes and shared state; HttpServer binds an address and runs the app, often across multiple worker threads.
- Handlers (extractors): async functions whose typed arguments (path, query, JSON, state) are extracted from the request automatically.
- Routing: route macros (
#[get("/path")]) or builder methods (.route(...), .service(...)) map paths and methods to handlers.
- Application state: shared data wrapped in
web::Data<T> injected into handlers; it must be thread-safe.
- Middleware: wraps handlers for cross-cutting concerns (logging, auth, compression) via the
wrap API.
- Responders: handler return types implementing
Responder are converted into HTTP responses.
Best practices
- Pin
actix-web = "4" and use a recent stable Rust toolchain as the docs require (https://actix.rs/docs/getting-started/).
- Share state with
web::Data instead of globals so it is cleanly injected and thread-safe.
- Use typed extractors (Json, Path, Query) so deserialization and validation happen at the boundary.
- Add the Logger middleware and structured error handling rather than panicking in handlers.
Common pitfalls
- Doing blocking work directly in an async handler → blocks the worker; offload with
web::block or an async client.
- Expecting non-Send state to be shared across workers →
App state must be thread-safe; wrap shared data in web::Data.
- Confusing the actor framework
actix with the web framework actix-web → for web servers depend on actix-web.
Examples
use actix_web::{get, App, HttpServer, Responder};
#[get("/")]
async fn hello() -> impl Responder {
"Hello, World!"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(hello))
.bind(("127.0.0.1", 8080))?
.run()
.await
}
Further reading
Related skills
- ../gin — comparable high-performance framework in Go
- ../aspnet-core — cross-platform compiled-language web framework (.NET)
1---2name: actix3description: Powerful, fast Rust web framework (actix-web) on Tokio with HTTP/1 and HTTP/2, routing, and middleware; consult when building Rust HTTP services.4domain: stack5category: backend6tags: [rust, actix-web, tokio, http, web-framework]7official_sources:8 - https://actix.rs/docs/9 - https://github.com/actix/actix-web10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/actix13---1415# Actix Web1617## Overview18actix-web is a powerful, pragmatic, and extremely fast web framework for Rust. It supports HTTP/1.x and HTTP/2, streaming and pipelining, powerful request routing with optional macros, and comprehensive middleware. Built on Tokio and running on stable Rust, it ranks among the fastest web frameworks in TechEmpower benchmarks. Read this when building Rust HTTP APIs and services.1920## Official sources21- Docs: https://actix.rs/docs/22- Repo: https://github.com/actix/actix-web23- Install / download: https://actix.rs/docs/getting-started/2425## Install / setup26```bash27cargo new hello-world28cd hello-world29```30```toml31# Cargo.toml — add the dependency (requires a recent stable Rust)32[dependencies]33actix-web = "4"34```3536## Core concepts37- App & HttpServer: an `App` registers routes and shared state; `HttpServer` binds an address and runs the app, often across multiple worker threads.38- Handlers (extractors): async functions whose typed arguments (path, query, JSON, state) are extracted from the request automatically.39- Routing: route macros (`#[get("/path")]`) or builder methods (`.route(...)`, `.service(...)`) map paths and methods to handlers.40- Application state: shared data wrapped in `web::Data<T>` injected into handlers; it must be thread-safe.41- Middleware: wraps handlers for cross-cutting concerns (logging, auth, compression) via the `wrap` API.42- Responders: handler return types implementing `Responder` are converted into HTTP responses.4344## Best practices45- Pin `actix-web = "4"` and use a recent stable Rust toolchain as the docs require (https://actix.rs/docs/getting-started/).46- Share state with `web::Data` instead of globals so it is cleanly injected and thread-safe.47- Use typed extractors (Json, Path, Query) so deserialization and validation happen at the boundary.48- Add the Logger middleware and structured error handling rather than panicking in handlers.4950## Common pitfalls51- Doing blocking work directly in an async handler → blocks the worker; offload with `web::block` or an async client.52- Expecting non-Send state to be shared across workers → `App` state must be thread-safe; wrap shared data in `web::Data`.53- Confusing the actor framework `actix` with the web framework `actix-web` → for web servers depend on `actix-web`.5455## Examples56```rust57use actix_web::{get, App, HttpServer, Responder};5859#[get("/")]60async fn hello() -> impl Responder {61 "Hello, World!"62}6364#[actix_web::main]65async fn main() -> std::io::Result<()> {66 HttpServer::new(|| App::new().service(hello))67 .bind(("127.0.0.1", 8080))?68 .run()69 .await70}71```7273## Further reading74- https://actix.rs/docs/getting-started/ — Getting started75- https://actix.rs/docs/extractors/ — Type-safe extractors7677## Related skills78- ../gin — comparable high-performance framework in Go79- ../aspnet-core — cross-platform compiled-language web framework (.NET)