37 lines
1.0 KiB
Rust
37 lines
1.0 KiB
Rust
//! 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, 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;
|
|
|
|
println!("Server stopped");
|
|
}
|
|
|
|
/// 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()))
|
|
}
|