Crates.io | http-handle |
lib.rs | http-handle |
version | 0.0.2 |
source | src |
created_at | 2024-10-13 15:37:21.491294 |
updated_at | 2024-10-13 19:19:48.22523 |
description | A fast and lightweight Rust library for handling HTTP requests and responses. |
homepage | https://http-handle.com/ |
repository | https://github.com/sebastienrousseau/http-handle |
max_upload_size | |
id | 1407429 |
size | 153,810 |
A Rust-based HTTP server for serving static websites.
• Website • Documentation • Report Bug • Request Feature • Contributing Guidelines
The http-handle
is a robust Rust library designed for serving static websites. It provides a simple yet efficient HTTP server implementation with features like request parsing, response generation, and basic security measures. The library is not intended to be a full-fledged web server but rather a lightweight solution for serving static files over HTTP for development and testing purposes.
Add this to your Cargo.toml
:
[dependencies]
http-handle = "0.0.2"
Here's a basic example of how to use http-handle
:
use http_handle::Server;
use std::thread;
use std::time::Duration;
fn main() -> std::io::Result<()> {
// Create a new server with an address and document root
let server = Server::new("127.0.0.1:8080", "./public");
// Run the server in a separate thread so it doesn't block
let server_handle = thread::spawn(move || {
server.start().expect("Server failed to start");
});
// Let the server run for 2 seconds before shutting it down
thread::sleep(Duration::from_secs(2));
println!("Server has been running for 2 seconds, shutting down...");
// In a real-world scenario, you would need to implement a proper shutdown signal
// This just exits the program after the duration.
Ok(())
}
This will start a server listening on 127.0.0.1:8080
, serving files from the ./public
directory.
For full API documentation, please visit docs.rs/http-handle.
To explore more examples, clone the repository and run the following command:
cargo run --example example_name
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under either of
at your option.
Special thanks to all contributors who have helped build the http-handle
library.