1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-16 05:22:00 +01:00
actix-web/src/lib.rs

231 lines
5.9 KiB
Rust
Raw Normal View History

//! Actix web is a small, pragmatic, and extremely fast web framework
//! for Rust.
2017-12-13 23:35:21 -08:00
//!
2018-01-09 10:08:06 -08:00
//! ```rust
2018-04-06 09:45:10 -07:00
//! use actix_web::{server, App, Path};
2018-01-09 10:08:06 -08:00
//! # use std::thread;
2017-12-13 23:35:21 -08:00
//!
2018-03-29 15:07:12 -07:00
//! fn index(info: Path<(String, u32)>) -> String {
//! format!("Hello {}! id:{}", info.0, info.1)
2017-12-13 23:35:21 -08:00
//! }
//!
//! fn main() {
2018-01-09 10:08:06 -08:00
//! # thread::spawn(|| {
2018-04-06 09:45:10 -07:00
//! server::new(
2018-03-31 00:16:55 -07:00
//! || App::new()
2018-03-29 15:07:12 -07:00
//! .resource("/{name}/{id}/index.html", |r| r.with(index)))
2018-01-09 10:08:06 -08:00
//! .bind("127.0.0.1:8080").unwrap()
//! .run();
//! # });
2017-12-13 23:35:21 -08:00
//! }
//! ```
//!
//! ## Documentation & community resources
//!
//! Besides the API documentation (which you are currently looking
//! at!), several other resources are available:
2017-12-13 23:35:21 -08:00
//!
2018-04-10 19:27:09 -07:00
//! * [User Guide](https://actix.rs/actix-web/guide/)
2018-01-11 18:49:30 -08:00
//! * [Chat on gitter](https://gitter.im/actix/actix)
2018-01-11 18:47:34 -08:00
//! * [GitHub repository](https://github.com/actix/actix-web)
//! * [Cargo package](https://crates.io/crates/actix-web)
//!
//! To get started navigating the API documentation you may want to
//! consider looking at the following pages:
//!
//! * [App](struct.App.html): This struct represents an actix-web
//! application and is used to configure routes and other common
//! settings.
//!
//! * [HttpServer](server/struct.HttpServer.html): This struct
//! represents an HTTP server instance and is used to instantiate and
//! configure servers.
//!
//! * [HttpRequest](struct.HttpRequest.html) and
//! [HttpResponse](struct.HttpResponse.html): These structs
//! represent HTTP requests and responses and expose various methods
//! for inspecting, creating and otherwise utilising them.
2017-12-13 23:35:21 -08:00
//!
//! ## Features
//!
//! * Supported *HTTP/1.x* and *HTTP/2.0* protocols
//! * Streaming and pipelining
//! * Keep-alive and slow requests handling
2018-02-26 14:33:56 -08:00
//! * `WebSockets` server/client
2017-12-13 23:35:21 -08:00
//! * Transparent content compression/decompression (br, gzip, deflate)
//! * Configurable request routing
2018-02-28 22:31:54 -08:00
//! * Graceful server shutdown
2017-12-13 23:35:21 -08:00
//! * Multipart streams
//! * SSL support with OpenSSL or `native-tls`
2018-03-07 21:39:20 -08:00
//! * Middlewares (`Logger`, `Session`, `CORS`, `CSRF`, `DefaultHeaders`)
//! * Built on top of [Actix actor framework](https://github.com/actix/actix)
//! * Supported Rust version: 1.21 or later
2017-10-06 21:48:14 -07:00
2017-11-24 10:28:43 -08:00
#![cfg_attr(actix_nightly, feature(
specialization, // for impl ErrorResponse for std::error::Error
))]
#![cfg_attr(feature = "cargo-clippy", allow(
2018-02-26 13:58:23 -08:00
decimal_literal_representation,suspicious_arithmetic_impl,))]
2017-10-06 21:48:14 -07:00
#[macro_use]
extern crate log;
extern crate time;
2018-01-27 22:03:03 -08:00
extern crate base64;
2017-10-06 21:48:14 -07:00
extern crate bytes;
extern crate byteorder;
2017-10-07 21:48:00 -07:00
extern crate sha1;
2017-10-16 19:21:24 -07:00
extern crate regex;
2017-10-06 21:48:14 -07:00
#[macro_use]
extern crate bitflags;
#[macro_use]
2017-12-29 01:01:31 -08:00
extern crate failure;
#[macro_use]
extern crate lazy_static;
#[macro_use]
2017-10-06 21:48:14 -07:00
extern crate futures;
2018-03-07 14:56:53 -08:00
extern crate futures_cpupool;
2017-10-06 21:48:14 -07:00
extern crate tokio_io;
2017-10-29 06:05:31 -07:00
extern crate tokio_core;
2017-12-27 11:22:27 -08:00
extern crate mio;
extern crate net2;
extern crate cookie;
2018-03-30 17:31:18 -07:00
extern crate http as modhttp;
2017-10-06 21:48:14 -07:00
extern crate httparse;
extern crate http_range;
2017-10-18 23:43:50 -07:00
extern crate mime;
2017-10-16 01:19:23 -07:00
extern crate mime_guess;
2018-03-06 00:43:25 -08:00
extern crate language_tags;
2018-01-27 22:03:03 -08:00
extern crate rand;
extern crate url;
2017-11-10 13:26:12 -08:00
extern crate libc;
#[macro_use] extern crate serde;
2017-11-15 20:06:28 -10:00
extern crate serde_json;
2018-03-26 15:58:30 -07:00
extern crate serde_urlencoded;
2017-11-06 01:24:49 -08:00
extern crate flate2;
2018-03-13 17:21:22 -07:00
#[cfg(feature="brotli")]
2017-11-06 01:24:49 -08:00
extern crate brotli2;
extern crate encoding;
extern crate percent_encoding;
extern crate smallvec;
extern crate num_cpus;
extern crate h2 as http2;
2018-01-27 22:03:03 -08:00
extern crate trust_dns_resolver;
2017-12-27 12:58:32 -08:00
#[macro_use] extern crate actix;
2017-10-06 21:48:14 -07:00
2017-12-03 18:51:52 -08:00
#[cfg(test)]
#[macro_use] extern crate serde_derive;
2017-11-15 20:06:28 -10:00
#[cfg(feature="tls")]
extern crate native_tls;
#[cfg(feature="tls")]
extern crate tokio_tls;
#[cfg(feature="openssl")]
extern crate openssl;
#[cfg(feature="openssl")]
extern crate tokio_openssl;
2017-10-06 21:48:14 -07:00
mod application;
2017-10-23 23:25:32 -07:00
mod body;
2017-10-06 21:48:14 -07:00
mod context;
mod de;
mod extractor;
mod handler;
2018-03-30 17:31:18 -07:00
mod header;
mod helpers;
mod httpmessage;
mod httprequest;
2017-10-15 09:33:17 -07:00
mod httpresponse;
2017-12-05 17:09:15 -08:00
mod info;
2017-12-20 17:51:28 -08:00
mod json;
2017-12-04 16:09:22 -08:00
mod route;
2017-12-06 16:26:27 -08:00
mod router;
2017-10-06 21:48:14 -07:00
mod resource;
mod param;
mod payload;
2017-11-24 22:15:52 -08:00
mod pipeline;
2018-03-26 23:10:31 -07:00
mod with;
2017-10-07 21:48:00 -07:00
pub mod client;
pub mod fs;
2017-10-09 23:07:32 -07:00
pub mod ws;
2017-11-15 20:06:28 -10:00
pub mod error;
2017-10-18 23:43:50 -07:00
pub mod multipart;
2017-12-26 19:59:41 -08:00
pub mod middleware;
2017-12-04 13:32:05 -08:00
pub mod pred;
pub mod test;
2018-01-11 18:35:05 -08:00
pub mod server;
pub use extractor::{Path, Form, Query};
2017-12-08 15:25:37 -08:00
pub use error::{Error, Result, ResponseError};
2017-11-10 13:42:32 -08:00
pub use body::{Body, Binary};
2018-01-11 18:35:05 -08:00
pub use json::Json;
2018-03-31 00:16:55 -07:00
pub use application::App;
pub use httpmessage::HttpMessage;
2017-12-07 16:40:29 -08:00
pub use httprequest::HttpRequest;
2017-11-26 22:53:28 -08:00
pub use httpresponse::HttpResponse;
2018-04-02 16:19:18 -07:00
pub use handler::{Either, Responder, AsyncResponder, FromRequest, FutureResponse, State};
2017-10-06 21:48:14 -07:00
pub use context::HttpContext;
2017-10-14 10:40:58 -07:00
#[doc(hidden)]
pub mod httpcodes;
2018-03-31 00:16:55 -07:00
#[doc(hidden)]
#[allow(deprecated)]
pub use application::Application;
2018-01-29 23:01:20 -08:00
#[cfg(feature="openssl")]
pub(crate) const HAS_OPENSSL: bool = true;
#[cfg(not(feature="openssl"))]
pub(crate) const HAS_OPENSSL: bool = false;
2018-03-06 17:34:46 -08:00
#[cfg(feature="tls")]
pub(crate) const HAS_TLS: bool = true;
#[cfg(not(feature="tls"))]
pub(crate) const HAS_TLS: bool = false;
2018-01-29 23:01:20 -08:00
2017-12-06 17:06:40 -08:00
pub mod dev {
//! The `actix-web` prelude for library developers
//!
//! The purpose of this module is to alleviate imports of many common actix traits
//! by adding a glob import to the top of actix heavy modules:
//!
//! ```
//! # #![allow(unused_imports)]
//! use actix_web::dev::*;
//! ```
2017-12-13 22:36:28 -08:00
pub use body::BodyStream;
2018-02-28 11:10:54 -08:00
pub use context::Drain;
2018-04-03 22:06:18 -07:00
pub use json::{JsonBody, JsonConfig};
2017-12-06 17:06:40 -08:00
pub use info::ConnectionInfo;
2018-04-02 16:19:18 -07:00
pub use handler::{Handler, Reply};
2018-04-04 21:13:48 -07:00
pub use extractor::{FormConfig, PayloadConfig};
pub use route::Route;
2018-04-02 11:18:31 -07:00
pub use router::{Router, Resource, ResourceType};
pub use resource::ResourceHandler;
pub use param::{FromParam, Params};
2018-03-28 21:58:08 -07:00
pub use httpmessage::{UrlEncoded, MessageBody};
2017-12-06 17:06:40 -08:00
pub use httpresponse::HttpResponseBuilder;
}
2018-03-30 17:31:18 -07:00
pub mod http {
//! Various HTTP related types
2018-03-30 17:31:18 -07:00
// re-exports
pub use modhttp::{Method, StatusCode, Version};
#[doc(hidden)]
pub use modhttp::{uri, Uri, Error, Extensions, HeaderMap, HttpTryFrom};
pub use http_range::HttpRange;
pub use cookie::{Cookie, CookieBuilder};
pub use helpers::NormalizePath;
pub mod header {
pub use ::header::*;
}
pub use header::ContentEncoding;
pub use httpresponse::ConnectionType;
}