Expand description
§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
Re-exports§
pub use router::GotchaRouter;
pub use crate::message::Message;
pub use crate::message::Messager;
pub use crate::openapi::Operable;
pub use task::TaskScheduler;
pub use axum;
pub use inventory;
pub use tracing;
pub use oas;
Modules§
Structs§
- Config
Wrapper - Gotcha
Config Loader - Gotcha
Context - Json
- JSON Extractor / Response.
- Lazy
- A value which is initialized on the first access.
- Path
- Extractor that will get captures from the URL and parse them using
serde
. - Query
- Extractor that deserializes query strings into some type.
- State
- Extractor for state.
Enums§
- Either
- The enum
Either
with variantsLeft
andRight
is a general purpose sum type with two cases.
Traits§
- Gotcha
App - Parameter
Provider - Responder
- Trait for generating responses.
- Schematic
Functions§
- delete
- Route
DELETE
requests to the given handler. - get
- Route
GET
requests to the given handler. - patch
- Route
PATCH
requests to the given handler. - post
- Route
POST
requests to the given handler. - put
- Route
PUT
requests to the given handler.
Attribute Macros§
- api
- async_
trait - debug_
handler - Generates better error messages when applied to handler functions.