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.54+
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#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
74#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
75#![cfg_attr(docsrs, feature(doc_auto_cfg))]
76
77pub use actix_http::{body, HttpMessage};
78#[cfg(feature = "cookies")]
79#[doc(inline)]
80pub use cookie;
81
82mod app;
83mod app_service;
84mod config;
85mod data;
86pub mod dev;
87pub mod error;
88mod extract;
89pub mod guard;
90mod handler;
91mod helpers;
92pub mod http;
93mod info;
94pub mod middleware;
95mod redirect;
96mod request;
97mod request_data;
98mod resource;
99mod response;
100mod rmap;
101mod route;
102pub mod rt;
103mod scope;
104mod server;
105mod service;
106pub mod test;
107mod thin_data;
108pub(crate) mod types;
109pub mod web;
110
111#[doc(inline)]
112pub use crate::error::Result;
113pub use crate::{
114    app::App,
115    error::{Error, ResponseError},
116    extract::FromRequest,
117    handler::Handler,
118    request::HttpRequest,
119    resource::Resource,
120    response::{CustomizeResponder, HttpResponse, HttpResponseBuilder, Responder},
121    route::Route,
122    scope::Scope,
123    server::HttpServer,
124    types::Either,
125};
126
127macro_rules! codegen_reexport {
128    ($name:ident) => {
129        #[cfg(feature = "macros")]
130        pub use actix_web_codegen::$name;
131    };
132}
133
134codegen_reexport!(main);
135codegen_reexport!(test);
136codegen_reexport!(route);
137codegen_reexport!(routes);
138codegen_reexport!(head);
139codegen_reexport!(get);
140codegen_reexport!(post);
141codegen_reexport!(patch);
142codegen_reexport!(put);
143codegen_reexport!(delete);
144codegen_reexport!(trace);
145codegen_reexport!(connect);
146codegen_reexport!(options);
147codegen_reexport!(scope);
148
149pub(crate) type BoxError = Box<dyn std::error::Error>;