A lightweight and asynchronous HTTP server written in Rust using the tokio
runtime. This server listens on 127.0.0.1:3000
and responds with a simple HTML page.
- Asynchronous TCP handling: Utilizes
tokio
for efficient, non-blocking IO operations. - Simple request handling: Parses incoming requests and responds with an HTML page.
- Concurrent connections: Handles multiple client connections simultaneously using
tokio::spawn
.
- Clone the repository:
git clone https://github.com/Cod-e-Codes/rust-simple-http-server.git cd rust-simple-http-server
- Build the project:
cargo build --release
- Run the project:
cargo run
-
Start the server:
cargo run
-
Open your browser and navigate to http://127.0.0.1:3000.
-
You will see the following response:
<html><body><h1>Welcome to Rust HTTP Server!</h1></body></html>
- Binding to a socket: The server binds to the IP address
127.0.0.1
on port3000
. - Listening for connections: Listens for incoming TCP connections using
tokio::net::TcpListener
. - Handling requests: Reads incoming data, logs the HTTP request, and sends a fixed HTML response.
- Concurrency: Each connection is handled in a separate asynchronous task (
tokio::spawn
).
GET / HTTP/1.1
Host: 127.0.0.1:3000
HTTP/1.1 200 OK
<html><body><h1>Welcome to Rust HTTP Server!</h1></body></html>
main.rs
: Contains the server logic, request handling, and response generation.
tokio
: Provides asynchronous runtime and utilities for handling networking tasks.
This project is licensed under the MIT License. See the LICENSE
file for details.
Contributions are welcome! Feel free to open an issue or submit a pull request.
- Add support for parsing HTTP headers.
- Extend the server to handle different routes.
- Implement a configuration file for customizable settings (e.g., port, IP address).
- Improve error handling and logging.