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