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
flate2
crate:- compresses the response body if the client supports it
- support for the following endpoints:
-
/
- returns200 OK
status code -
/echo/<string_to_return>
- echoes the string passed by user in the URL -
/user-agent
- echoes theUser-Agent
header value -
/files/{filename}
- returns the content of the file with the namefilename
in the specified directory -
/files/{filename}
- saves the content of the response to the file with the namefilename
in the specified directory
-
- Ensure you have
cargo (>=1.70)
installed locally - Run
./your_server.sh
to 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-server
onhttp://127.0.0.1:4221
. Subsequent runs will be fast. - Open a new tab in the terminal and send requests to the server using
curl
ornetcat
. To test the performance of the server, you can use theoha
CLI 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 useoha
is shown below:
# Send 10000 requests with 10 concurrent connections
$ oha -n 10000 -c 10 http://127.0.0.1:4221/echo/hello