1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
//! # Saphir is a fully async-await http server framework for rust //! The goal is to give low-level control to your web stack (as hyper does) //! without the time consuming task of doing everything from scratch. //! //! Just `use` the prelude module, and you're ready to go! //! //! # Quick Overview //! //! Saphir provide multiple functionality through features. To try it out //! without fuss, we suggest that use all the features: //! //! ```toml //! saphir = { version = "2.0.0", features = ["full"] } //! ``` //! //! Then bootstrapping the server is as easy as: //! //! ```rust //! use saphir::prelude::*; //! //! struct TestController {} //! //! #[controller] //! impl TestController { //! #[get("/{var}/print")] //! async fn print_test(&self, var: String) -> (u16, String) { //! (200, var) //! } //! } //! //! async fn test_handler(mut req: Request) -> (u16, Option<String>) { //! (200, req.captures_mut().remove("variable")) //! } //! //! #[tokio::main] //! async fn main() -> Result<(), SaphirError> { //! env_logger::init(); //! //! let server = Server::builder() //! .configure_listener(|l| { //! l.interface("127.0.0.1:3000") //! }) //! .configure_router(|r| { //! r.route("/{variable}/print", Method::GET, test_handler) //! .controller(TestController {}) //! }) //! .build(); //! //! // Start server with //! // server.run().await //! # Ok(()) //! } //! ``` //! # Saphir's Features //! //! Even though we strongly recommend that you use at least the `macro` feature, //! Saphir will work without any of the following feature, Saphir's features //! don't rely on each other to work. //! //! - `macro` : Enable the `#[controller]` macro attribute for code generation, //! Recommended and active by default //! - `https` : Provide everything to allow Saphir server to listen an accept //! HTTPS traffic //! - `json` : Add the `Json` wrapper type to simplify working with json data //! - `form` : Add the `Form` wrapper type to simplify working with urlencoded //! data //! //! *_More feature will be added in the future_* #[macro_use] extern crate log; /// pub mod body; /// pub mod controller; /// pub mod cookie; /// Error definitions pub mod error; /// pub mod extension; /// #[cfg(feature = "file")] pub mod file; /// pub mod guard; /// Definition of types which can handle an http request pub mod handler; /// Context enveloping every request <-> response pub mod http_context; /// Saphir macro for code generation #[cfg(feature = "macro")] pub mod macros; /// pub mod middleware; /// The async Multipart Form-Data representation #[cfg(feature = "multipart")] pub mod multipart; /// #[cfg(feature = "redirect")] pub mod redirect; /// The Http Request type pub mod request; /// Definition of type which can map to a response pub mod responder; /// The Http Response type pub mod response; /// pub mod router; /// Server implementation and default runtime pub mod server; /// pub mod utils; /// pub use http; #[doc(hidden)] pub use hyper; /// Contains everything you need to bootstrap your http server /// /// ```rust /// use saphir::prelude::*; /// /// // implement magic /// ``` pub mod prelude { /// pub use crate::body::Body; /// pub use crate::body::Bytes; /// #[cfg(feature = "form")] pub use crate::body::Form; /// #[cfg(feature = "json")] pub use crate::body::Json; /// pub use crate::controller::Controller; /// pub use crate::controller::ControllerEndpoint; /// pub use crate::controller::EndpointsBuilder; /// pub use crate::cookie::Cookie; /// pub use crate::cookie::CookieBuilder; /// pub use crate::cookie::CookieJar; /// pub use crate::error::SaphirError; /// pub use crate::extension::Ext; /// pub use crate::extension::Extensions; /// #[cfg(feature = "file")] pub use crate::file::File; /// pub use crate::guard::Guard; /// pub use crate::handler::Handler; #[cfg(feature = "operation")] pub use crate::http_context::operation::OperationId; /// pub use crate::http_context::HttpContext; /// #[cfg(feature = "macro")] pub use crate::macros::*; /// pub use crate::middleware::Middleware; /// pub use crate::middleware::MiddlewareChain; /// #[cfg(feature = "multipart")] pub use crate::multipart::Multipart; /// #[cfg(feature = "redirect")] pub use crate::redirect::Redirect; /// pub use crate::request::FromRequest; /// pub use crate::request::Request; /// pub use crate::responder::Responder; /// pub use crate::response::Builder; /// pub use crate::response::Response; /// pub use crate::server::Server; /// pub use crate::server::Stack; /// pub use http::header; /// pub use http::Method; /// pub use http::StatusCode; /// pub use http::Uri; /// pub use http::Version; }