This is a repo for Rust solutions to the http-server challenge on Codecrafters.
The entry point for this http-server implementation is in src/main.rs. This simple http-server
implementation includes:
- user-friendly API for parsing HTTP requests
- user-friendly, elegant, and type-safe API for building HTTP responses
- support for concurrent connections handling using thread pool with a configurable number of threads (deprecated in favor of async/await)
- support for concurrent connections handling using multi-threading with async/await
- compression support for the server using the
flate2crate:- compresses the response body if the client supports it
- support for the following endpoints:
-
/- returns200 OKstatus code -
/echo/<string_to_return>- echoes the string passed by user in the URL -
/user-agent- echoes theUser-Agentheader value -
/files/{filename}- returns the content of the file with the namefilenamein the specified directory -
/files/{filename}- saves the content of the response to the file with the namefilenamein the specified directory
-
- Ensure you have
cargo (>=1.70)installed locally - Run
./your_server.shto run your program, which is implemented insrc/main.rs. This command compiles your Rust project, so it might be slow the first time you run thehttp-serveronhttp://127.0.0.1:4221. Subsequent runs will be fast. - Open a new tab in the terminal and send requests to the server using
curlornetcat. To test the performance of the server, you can use theohaCLI tool to send a large number of concurrent requests to the server and get the performance metrics in a nice TUI interface. An example of how to useohais shown below:
# Send 10000 requests with 10 concurrent connections
$ oha -n 10000 -c 10 http://127.0.0.1:4221/echo/hello