SLHS (Simple Light-weight HTTP Server)
SLHS is a simple, no-frills HTTP server library written in Rust. It aims to provide a minimalistic yet functional base for building web services without the overhead of larger frameworks.
Features
- Simple Routing: Define
GETandPOSTendpoints with ease. - Basic Request/Response Handling: Access headers, body, URL parameters, and set response status and headers.
- Optional Compression: Support for
gzipandbrotlicompression (requires feature flags). - Thread Pool: Uses a simple thread pool for handling concurrent requests.
Installation
Add SLHS to your Cargo.toml with:
To enable compression, add the respective features with:
Examples
1. Basic Server
This example sets up a server that listens on 127.0.0.1:8080 and responds to a GET request at the root path / and a POST request at /submit.
use *;
2. Handling URL Parameters and Custom Headers
This example demonstrates how to access URL query parameters and set custom response headers using the headers! macro.
use *;
3. Response Status Codes and Body Compression
SLHS automatically handles 404 Not Found and 405 Method Not Allowed. You can explicitly set other statuses. If compression features are enabled and the client supports it via Accept-Encoding header, the response body will be compressed.
use *;
Contributing
Feel free to open issues or submit pull requests!
License
This project is licensed under the MIT License.