smolserver - a small http-server written in Rust
-
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.
-
GET /
: Returns HTTP 200 for index routes. -
GET /user-agent
: Returns HTTP 200 and echoes back theUser-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.
This is an excellent project to understand:
- Basic HTTP protocol operations
- Socket programming in Rust
- Multi-threading
- File I/O
- Simple routing logic
This project is open-sourced under the MIT license. See the License file for more information. Free forever.
Happy coding! 🦀