https://github.com/cristicretu/smolserver
a minimalist http server in Rust
https://github.com/cristicretu/smolserver
http-server rust rust-http
Last synced: 8 days ago
JSON representation
a minimalist http server in Rust
- Host: GitHub
- URL: https://github.com/cristicretu/smolserver
- Owner: cristicretu
- License: mit
- Created: 2023-10-22T19:02:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-28T17:23:07.000Z (over 2 years ago)
- Last Synced: 2024-05-02T02:41:47.097Z (about 2 years ago)
- Topics: http-server, rust, rust-http
- Language: Rust
- Homepage:
- Size: 285 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
smolserver - a small http-server written in Rust
## ✨ Features
- **File Handling**: Supports both reading and creating files. Perfect for file manipulation operations through HTTP requests.
- **User Agent Routing**: Special handling for requests with the `User-Agent` header.
- **Echo Route**: You can echo back whatever is appended to the `/echo/` endpoint, making it useful for quick tests.
- **Educational**: Designed primarily as a learning exercise to understand the workings of a basic HTTP server in Rust.
- **Extensible**: Despite its simplicity, the server can be further developed and integrated into larger projects.
## 🛠 How It Works
- **`GET /`**: Returns HTTP 200 for index routes.
- **`GET /user-agent`**: Returns HTTP 200 and echoes back the `User-Agent` if present in the request headers.
- **`GET /echo/{message}`**: Returns HTTP 200 and echoes back the `{message}`. For example, a GET request to `/echo/hello` would return "hello".
- **`GET /files/{name_of_file}`**: If the file exists in the directory (provided as a command line argument), it returns the file with HTTP 200. Otherwise, returns HTTP 404.
- **`POST /files/{name_of_file}`**: Creates a new file in the directory (provided as a command line argument) with the content from the request body. Returns HTTP 201 with a success message.
## 💡 What to Learn
This is an excellent project to understand:
- Basic HTTP protocol operations
- Socket programming in Rust
- Multi-threading
- File I/O
- Simple routing logic
## 📜 License
This project is open-sourced under the MIT license. See [the License file](LICENSE) for more information. Free forever.
Happy coding! 🦀