refactor: unify error handling, graceful shutdown, and constants across framework

This commit is contained in:
2026-04-29 23:23:46 +02:00
committed by ForgeCode
parent db7b26864b
commit f37befacdd
14 changed files with 1990 additions and 182 deletions
+21 -5
View File
@@ -1,20 +1,36 @@
//! Servme HTTP Framework - Example Application
//!
//! This example demonstrates the basic usage of the Servme framework
//! including server configuration, middleware setup, and request handling.
use http_body_util::Full;
use hyper::{
Request, Response,
body::{Bytes, Incoming},
};
use servme::{Responder, Server};
use std::convert::Infallible;
use servme::{Responder, Server, ServerError};
/// Main entry point for the example server.
///
/// This example creates a simple HTTP server that responds with a greeting.
#[tokio::main]
async fn main() {
println!("Starting Servme example server...");
println!("Server will listen on http://127.0.0.1:8080");
println!("Press Ctrl+C to stop");
Server::builder()
.address("127.0.0.1", 8080)
.build()
.run(handler)
.await
.await;
println!("Server stopped");
}
async fn handler(req: Request<Incoming>) -> Result<Response<Full<Bytes>>, Infallible> {
Responder::ok(format!("Hello World! {}", req.uri()))
/// Request handler function.
///
/// Receives incoming HTTP requests and returns appropriate responses.
async fn handler(req: Request<Incoming>) -> Result<Response<Full<Bytes>>, ServerError> {
Responder::ok(format!("Hello World! Path: {}", req.uri()))
}