Crate rustful [−] [src]
A light HTTP framework with REST-like features. The main purpose of Rustful is to create a simple, modular and non-intrusive foundation for HTTP applications. It has a mainly stateless structure, which naturally allows it to run both as one single server and as multiple instances in a cluster.
A new server is created using the Server
type, which contains
all the necessary settings as fields:
#[macro_use] extern crate rustful; use rustful::{Server, Handler, Context, Response, TreeRouter}; struct Greeting(&'static str); impl Handler for Greeting { fn handle_request(&self, context: Context, response: Response) { //Check if the client accessed /hello/:name or /good_bye/:name if let Some(name) = context.variables.get("name") { //Use the value of :name response.send(format!("{}, {}", self.0, name)); } else { response.send(self.0) } } } let my_router = insert_routes!{ //Create a new TreeRouter TreeRouter::new() => { //Receive GET requests to /hello and /hello/:name "hello" => { Get: Greeting("hello"), ":name" => Get: Greeting("hello") }, //Receive GET requests to /good_bye and /good_bye/:name "good_bye" => { Get: Greeting("good bye"), ":name" => Get: Greeting("good bye") } } }; Server { //Use a closure to handle requests. handlers: my_router, //Set the listening port to `8080`. host: 8080.into(), //Fill out everything else with default values. ..Server::default() }.run();
Reexports
pub use self::server::Server; |
pub use self::context::Context; |
pub use self::response::Response; |
pub use self::response::Error; |
pub use self::handler::Handler; |
pub use self::router::Router; |
Modules
context |
Handler context and request body reading extensions. |
file |
File related utilities. |
filter |
Request and context filters. |
handler |
Request handlers. |
header |
Headers container, and common header fields. |
mime |
Re-exporting the mime crate, for convenience. |
response |
Response writers. |
router |
Routers stores request handlers, using an HTTP method and a path as keys. |
server |
Server configuration and instance. |
Macros
content_type! |
A macro for making content types. |
insert_routes! |
The |
Structs
TreeRouter |
Stores handlers, using an HTTP method and a route as key. |
Enums
HttpError |
A set of errors that can occur parsing HTTP streams. |
HttpVersion |
Represents a version of the HTTP spec. |
Method |
The Request Method (VERB) |
StatusCode |
An HTTP status code ( |
Type Definitions
HttpResult |