Crates.io | lsdserver |
lib.rs | lsdserver |
version | |
source | src |
created_at | 2025-03-17 11:58:36.00538+00 |
updated_at | 2025-03-17 11:58:36.00538+00 |
description | Lightweight dependency-free HTTP server Library in Rust |
homepage | https://github.com/linuxfanboy4/lsdserver.git |
repository | |
max_upload_size | |
id | 1595382 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
LSD Server is a lightweight, dependency-free HTTP server library written in Rust. It is designed to be simple, fast, and easy to use, making it an ideal choice for serving static files or building small web applications. The library is minimalistic, with no external dependencies, ensuring that your project remains lightweight and efficient.
To add LSD Server to your project, use Cargo:
cargo add lsdserver
This will add the latest version of LSD Server to your Cargo.toml
file.
Here's a simple example of how to use LSD Server to serve static files:
use lsdserver::{start_server, handle_connection};
fn main() {
// Start the server on localhost:8080
start_server("127.0.0.1:8080");
}
This will start an HTTP server on 127.0.0.1:8080
. By default, the server will serve files from the current directory. For example, if you have an index.html
file in the root directory, it will be served when you navigate to http://127.0.0.1:8080/
.
The handle_connection
function is responsible for processing incoming HTTP requests. It reads the request, determines the requested file, and serves it with the appropriate content type. If the file does not exist, it returns a 404 Not Found response.
The start_server
function binds the server to the specified address and starts listening for incoming connections. It prints a message to the console indicating that the server has started.
LSD Server is designed to be simple, but it can be easily extended to handle more complex use cases. For example, you can modify the handle_connection
function to implement custom routing, middleware, or other advanced features.
LSD Server is licensed under the MIT License. See the LICENSE file for more details.