14 releases
0.2.2 | Dec 31, 2024 |
---|---|
0.1.12 | Oct 31, 2023 |
0.1.6 | Jun 30, 2023 |
0.1.5 | Feb 22, 2023 |
0.1.0 | Aug 4, 2019 |
#579 in HTTP server
143 downloads per month
335KB
741 lines
Gotcha
Gotcha is an enhanced web framework based on Axum, providing additional features and conveniences for building web applications in Rust.
Features
- Built on top of Axum for high performance and reliability
- OpenAPI documentation generation (optional)
- Prometheus metrics integration (optional)
- CORS support (optional)
- Static file serving (optional)
- Task scheduling
- Configuration management
- Message system
- State management
Example
use gotcha::{async_trait, ConfigWrapper, GotchaApp, GotchaContext, GotchaRouter, Responder, State};
use serde::{Deserialize, Serialize};
pub async fn hello_world(_state: State<ConfigWrapper<Config>>) -> impl Responder {
"hello world"
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Config {
pub name: String,
}
pub struct App {}
#[async_trait]
impl GotchaApp for App {
type State = ();
type Config = Config;
fn routes(&self, router: GotchaRouter<GotchaContext<Self::State, Self::Config>>) -> GotchaRouter<GotchaContext<Self::State, Self::Config>> {
router.get("/", hello_world)
}
async fn state(&self, _config: &ConfigWrapper<Self::Config>) -> Result<Self::State, Box<dyn std::error::Error>> {
Ok(())
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
App {}.run().await?;
Ok(())
}
Optional Features
openapi
- Enables OpenAPI documentation generationprometheus
- Enables Prometheus metricscors
- Enables CORS supportstatic_files
- Enables static file serving capabilities
Dependencies
~14–23MB
~330K SLoC