Gotham is a flexible Rust web framework that promotes stability, safety, security and speed.
Gotham web framework is a flexible web framework focused on promoting stability, safety, security, and speed.
Here are the principal functionalities and features of the Gotham web framework:
Built with Rust: Gotham is built with Rust, a language focused on safety, speed, and concurrency. This provides the performance and control of a low-level language combined with high-level abstractions.
Stability Focused: The framework targets stable Rust and is automatically tested against Rust beta and nightly releases.
Performance: It operates with No Garbage Collection, benefiting from Rust's memory safety guarantees, leading to predictable performance. It is described as Blazingly Fast, with completed requests (including the 99th percentile) measured in microseconds (µs).
Typing: Gotham is Statically Typed, ensuring the application is correctly expressed at compile time.
Asynchronous Processing: It is Async Everything. It leverages Tokio and Hyper (a fast server that provides an elegant layer over stringly typed HTTP) to enhance its asynchronous capabilities.
Handlers: Applications are built around Handler functions that are invoked in response to a request.
Router: The framework uses a Router to dispatch requests.
The router results in a tree of routes.
It considers both the HTTP verb (like GET, HEAD, POST, PUT, PATCH, DELETE) and the request path when determining a route match.
It allows associating a single path with multiple HTTP verbs, delegating to unique or shared handlers.
If no match is found, a 404 is returned.
It supports route scoping.
Server Start: Servers are started using gotham::start, which takes the listening address and the router configuration.
State: The core mechanism for passing data within Gotham is the State. Data can be stored, retrieved, and removed from the state.
Query String Extractors: Gotham provides mechanisms for extracting query string name/value pairs in a type-safe way.
The router attempts to extract data from the query string and store it in the State before handing control to the handler.
Extraction structs require implementing serde::de::Deserialize, gotham::state::data::StateData, and gotham::router::response::extender::StaticResponseExtender.
This extraction process ensures that all type safety requirements are met. If the query string data is bad, the router automatically refuses the request with an HTTP 400 (BadRequest) response status code.
Middleware Implementation: Middleware requires implementing the NewMiddleware and Middleware traits. Middleware logic can be executed both before and after the handler for the route runs.
Pipelines: Middleware is added to and referenced from a Pipeline. A pipeline guarantees that all middleware types are called in the established order.
Sharing State Across Handlers: Gotham allows sharing state safely across handlers. This is achieved using the StateMiddleware. Data intended for sharing (e.g., a RequestCounter) must be protected using Arc (for thread sharing) and Mutex (for safe modification).
Testing: The framework includes a TestServer utility to facilitate testing handlers and routes.
API: Links are provided to the GitHub repository, Documentation, Gitter Chat, Blog, and Crates.io.