Skip to main content

actix_web/
lib.rs

1//! Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
2//!
3//! # Examples
4//! ```no_run
5//! use actix_web::{get, web, App, HttpServer, Responder};
6//!
7//! #[get("/hello/{name}")]
8//! async fn greet(name: web::Path<String>) -> impl Responder {
9//!     format!("Hello {}!", name)
10//! }
11//!
12//! #[actix_web::main] // or #[tokio::main]
13//! async fn main() -> std::io::Result<()> {
14//!     HttpServer::new(|| {
15//!         App::new().service(greet)
16//!     })
17//!     .bind(("127.0.0.1", 8080))?
18//!     .run()
19//!     .await
20//! }
21//! ```
22//!
23//! # Documentation & Community Resources
24//! In addition to this API documentation, several other resources are available:
25//!
26//! * [Website & User Guide](https://actix.rs/)
27//! * [Examples Repository](https://github.com/actix/examples)
28//! * [Community Chat on Discord](https://discord.gg/NWpN5mmg3x)
29//!
30//! To get started navigating the API docs, you may consider looking at the following pages first:
31//!
32//! * [`App`]: This struct represents an Actix Web application and is used to
33//!   configure routes and other common application settings.
34//!
35//! * [`HttpServer`]: This struct represents an HTTP server instance and is
36//!   used to instantiate and configure servers.
37//!
38//! * [`web`]: This module provides essential types for route registration as well as
39//!   common utilities for request handlers.
40//!
41//! * [`HttpRequest`] and [`HttpResponse`]: These
42//!   structs represent HTTP requests and responses and expose methods for creating, inspecting,
43//!   and otherwise utilizing them.
44//!
45//! # Features
46//! - Supports HTTP/1.x and HTTP/2
47//! - Streaming and pipelining
48//! - Powerful [request routing](https://actix.rs/docs/url-dispatch/) with optional macros
49//! - Full [Tokio](https://tokio.rs) compatibility
50//! - Keep-alive and slow requests handling
51//! - Client/server [WebSockets](https://actix.rs/docs/websockets/) support
52//! - Transparent content compression/decompression (br, gzip, deflate, zstd)
53//! - Multipart streams
54//! - Static assets
55//! - SSL support using OpenSSL or Rustls
56//! - Middlewares ([Logger, Session, CORS, etc](middleware))
57//! - Integrates with the [`awc` HTTP client](https://docs.rs/awc/)
58//! - Runs on stable Rust 1.89+
59//!
60//! # Crate Features
61//! - `cookies` - cookie (v0.16) support (enabled by default)
62//! - `cookies-0_18` - cookie (v0.18) support through `cookie_0_18` and methods ending in `_0_18`.
63//!   Both cookie features can be enabled together.
64//! - `macros` - routing and runtime macros (enabled by default)
65//! - `compress-brotli` - brotli content encoding compression support (enabled by default)
66//! - `compress-gzip` - gzip and deflate content encoding compression support (enabled by default)
67//! - `compress-zstd` - zstd content encoding compression support (enabled by default)
68//! - `http2` - HTTP/2 support (enabled by default)
69//! - `openssl` - HTTPS support via `openssl` crate
70//! - `rustls` - HTTPS support via `rustls` 0.20 crate
71//! - `rustls-0_21` - HTTPS support via `rustls` 0.21 crate
72//! - `rustls-0_22` - HTTPS support via `rustls` 0.22 crate
73//! - `rustls-0_23` - HTTPS support via `rustls` 0.23 crate
74//! - `secure-cookies` - secure cookies support
75//!
76//! ## Experimental features
77//! To enable faster release iterations, we mark some features as experimental.
78//! These features are prefixed with `experimental` and a breaking change may happen at any release.
79//! Please use them in a production environment at your own risk.
80//!
81//! - `experimental-introspection` - route and method reporting utilities for local diagnostics
82//!   and tooling. See `examples/introspection.rs` and `examples/introspection_multi_servers.rs`.
83
84#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
85#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
86#![cfg_attr(docsrs, feature(doc_cfg))]
87
88#[cfg(all(test, feature = "macros"))]
89extern crate self as actix_web;
90
91pub use actix_http::{body, HttpMessage};
92#[cfg(feature = "cookies")]
93#[doc(inline)]
94pub use cookie;
95#[cfg(feature = "cookies-0_18")]
96#[doc(inline)]
97pub use cookie_0_18;
98pub use mime;
99mod app;
100mod app_service;
101mod config;
102mod data;
103pub mod dev;
104pub mod error;
105mod extract;
106pub mod guard;
107mod handler;
108mod helpers;
109pub mod http;
110mod info;
111pub mod middleware;
112mod redirect;
113mod request;
114mod request_data;
115mod resource;
116mod response;
117mod rmap;
118mod route;
119pub mod rt;
120mod scope;
121mod server;
122mod service;
123pub mod test;
124mod thin_data;
125pub(crate) mod types;
126pub mod web;
127
128#[cfg(feature = "experimental-introspection")]
129pub mod introspection;
130
131#[doc(inline)]
132pub use crate::error::Result;
133pub use crate::{
134    app::App,
135    error::{Error, ResponseError},
136    extract::FromRequest,
137    handler::Handler,
138    request::HttpRequest,
139    resource::Resource,
140    response::{CustomizeResponder, HttpResponse, HttpResponseBuilder, Responder},
141    route::Route,
142    scope::Scope,
143    server::HttpServer,
144    types::Either,
145};
146
147macro_rules! codegen_reexport {
148    ($name:ident) => {
149        #[cfg(feature = "macros")]
150        pub use actix_web_codegen::$name;
151    };
152}
153
154codegen_reexport!(connect);
155codegen_reexport!(delete);
156codegen_reexport!(get);
157codegen_reexport!(head);
158codegen_reexport!(main);
159codegen_reexport!(options);
160codegen_reexport!(patch);
161codegen_reexport!(post);
162codegen_reexport!(put);
163codegen_reexport!(query);
164codegen_reexport!(route);
165codegen_reexport!(routes);
166codegen_reexport!(scope);
167codegen_reexport!(test);
168codegen_reexport!(trace);
169
170pub(crate) type BoxError = Box<dyn std::error::Error>;