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//! - `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
86pub use actix_http::{body, HttpMessage};
87#[cfg(feature = "cookies")]
88#[doc(inline)]
89pub use cookie;
90pub use mime;
91mod app;
92mod app_service;
93mod config;
94mod data;
95pub mod dev;
96pub mod error;
97mod extract;
98pub mod guard;
99mod handler;
100mod helpers;
101pub mod http;
102mod info;
103pub mod middleware;
104mod redirect;
105mod request;
106mod request_data;
107mod resource;
108mod response;
109mod rmap;
110mod route;
111pub mod rt;
112mod scope;
113mod server;
114mod service;
115pub mod test;
116mod thin_data;
117pub(crate) mod types;
118pub mod web;
119
120#[cfg(feature = "experimental-introspection")]
121pub mod introspection;
122
123#[doc(inline)]
124pub use crate::error::Result;
125pub use crate::{
126 app::App,
127 error::{Error, ResponseError},
128 extract::FromRequest,
129 handler::Handler,
130 request::HttpRequest,
131 resource::Resource,
132 response::{CustomizeResponder, HttpResponse, HttpResponseBuilder, Responder},
133 route::Route,
134 scope::Scope,
135 server::HttpServer,
136 types::Either,
137};
138
139macro_rules! codegen_reexport {
140 ($name:ident) => {
141 #[cfg(feature = "macros")]
142 pub use actix_web_codegen::$name;
143 };
144}
145
146codegen_reexport!(main);
147codegen_reexport!(test);
148codegen_reexport!(route);
149codegen_reexport!(routes);
150codegen_reexport!(head);
151codegen_reexport!(get);
152codegen_reexport!(post);
153codegen_reexport!(patch);
154codegen_reexport!(put);
155codegen_reexport!(delete);
156codegen_reexport!(trace);
157codegen_reexport!(connect);
158codegen_reexport!(options);
159codegen_reexport!(scope);
160
161pub(crate) type BoxError = Box<dyn std::error::Error>;