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.88+
59//!
60//! # Crate Features
61//! - `cookies` - cookies support (enabled by default)
62//! - `macros` - routing and runtime macros (enabled by default)
63//! - `compress-brotli` - brotli content encoding compression support (enabled by default)
64//! - `compress-gzip` - gzip and deflate content encoding compression support (enabled by default)
65//! - `compress-zstd` - zstd content encoding compression support (enabled by default)
66//! - `openssl` - HTTPS support via `openssl` crate, supports `HTTP/2`
67//! - `rustls` - HTTPS support via `rustls` 0.20 crate, supports `HTTP/2`
68//! - `rustls-0_21` - HTTPS support via `rustls` 0.21 crate, supports `HTTP/2`
69//! - `rustls-0_22` - HTTPS support via `rustls` 0.22 crate, supports `HTTP/2`
70//! - `rustls-0_23` - HTTPS support via `rustls` 0.23 crate, supports `HTTP/2`
71//! - `secure-cookies` - secure cookies support
72//!
73//! ## Experimental features
74//! To enable faster release iterations, we mark some features as experimental.
75//! These features are prefixed with `experimental` and a breaking change may happen at any release.
76//! Please use them in a production environment at your own risk.
77//!
78//! - `experimental-introspection` - route and method reporting utilities for local diagnostics
79//!   and tooling. See `examples/introspection.rs` and `examples/introspection_multi_servers.rs`.
80
81#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
82#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
83#![cfg_attr(docsrs, feature(doc_cfg))]
84
85pub use actix_http::{body, HttpMessage};
86#[cfg(feature = "cookies")]
87#[doc(inline)]
88pub use cookie;
89pub use mime;
90mod app;
91mod app_service;
92mod config;
93mod data;
94pub mod dev;
95pub mod error;
96mod extract;
97pub mod guard;
98mod handler;
99mod helpers;
100pub mod http;
101mod info;
102pub mod middleware;
103mod redirect;
104mod request;
105mod request_data;
106mod resource;
107mod response;
108mod rmap;
109mod route;
110pub mod rt;
111mod scope;
112mod server;
113mod service;
114pub mod test;
115mod thin_data;
116pub(crate) mod types;
117pub mod web;
118
119#[cfg(feature = "experimental-introspection")]
120pub mod introspection;
121
122#[doc(inline)]
123pub use crate::error::Result;
124pub use crate::{
125    app::App,
126    error::{Error, ResponseError},
127    extract::FromRequest,
128    handler::Handler,
129    request::HttpRequest,
130    resource::Resource,
131    response::{CustomizeResponder, HttpResponse, HttpResponseBuilder, Responder},
132    route::Route,
133    scope::Scope,
134    server::HttpServer,
135    types::Either,
136};
137
138macro_rules! codegen_reexport {
139    ($name:ident) => {
140        #[cfg(feature = "macros")]
141        pub use actix_web_codegen::$name;
142    };
143}
144
145codegen_reexport!(main);
146codegen_reexport!(test);
147codegen_reexport!(route);
148codegen_reexport!(routes);
149codegen_reexport!(head);
150codegen_reexport!(get);
151codegen_reexport!(post);
152codegen_reexport!(patch);
153codegen_reexport!(put);
154codegen_reexport!(delete);
155codegen_reexport!(trace);
156codegen_reexport!(connect);
157codegen_reexport!(options);
158codegen_reexport!(scope);
159
160pub(crate) type BoxError = Box<dyn std::error::Error>;