{"id":21071294,"url":"https://github.com/yisuschrist/codecrafters-http-server-rust","last_synced_at":"2026-05-19T18:37:36.807Z","repository":{"id":198962100,"uuid":"701901020","full_name":"YisusChrist/codecrafters-http-server-rust","owner":"YisusChrist","description":"Welcome to the Build your own HTTP server challenge!","archived":false,"fork":false,"pushed_at":"2023-10-07T22:50:45.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T21:58:08.691Z","etag":null,"topics":["codecrafters","rust"],"latest_commit_sha":null,"homepage":"https://app.codecrafters.io/courses/http-server","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YisusChrist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-07T22:44:25.000Z","updated_at":"2023-12-24T13:09:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"70d6f892-5fed-45fa-9bee-533a25cc524a","html_url":"https://github.com/YisusChrist/codecrafters-http-server-rust","commit_stats":null,"previous_names":["yisuschrist/codecrafters-http-server-rust"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YisusChrist%2Fcodecrafters-http-server-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YisusChrist%2Fcodecrafters-http-server-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YisusChrist%2Fcodecrafters-http-server-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YisusChrist%2Fcodecrafters-http-server-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YisusChrist","download_url":"https://codeload.github.com/YisusChrist/codecrafters-http-server-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243514223,"owners_count":20303082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codecrafters","rust"],"created_at":"2024-11-19T18:51:32.454Z","updated_at":"2025-12-27T22:25:27.048Z","avatar_url":"https://github.com/YisusChrist.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![progress-banner](https://backend.codecrafters.io/progress/http-server/1a63bb07-bebc-4e1a-822d-541074c7b926)](https://app.codecrafters.io/users/YisusChrist?r=2qF)\n\nThis is a starting point for Rust solutions to the\n[\"Build Your Own HTTP server\" Challenge](https://app.codecrafters.io/courses/http-server/overview).\n\n[HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) is the\nprotocol that powers the web. In this challenge, you'll build a HTTP/1.1 server\nthat is capable of serving multiple clients.\n\nAlong the way you'll learn about TCP servers,\n[HTTP request syntax](https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html),\nand more.\n\n**Note**: If you're viewing this repo on GitHub, head over to\n[codecrafters.io](https://codecrafters.io) to try the challenge.\n\n# Introduction\n\nWelcome to the Build your own HTTP server challenge!\n\nIn this challenge, you'll build a toy HTTP server that's capable of handling GET/POST requests. Along the way, we'll learn about TCP connections, HTTP headers, HTTP verbs, handling multiple connections and more.\n\n# Repository Setup\n\nWe've prepared a starter repository with some Rust code for you.\n\nStep 1: Clone the repository.\n\n```sh\ngit clone https://git.codecrafters.io/0175455b294ede53 codecrafters-http-server-rust \u0026\u0026 cd codecrafters-http-server-rust\n```\n\nStep 2: Push an empty commit.\n\n```sh\ngit commit --allow-empty -m 'test' \u0026\u0026 git push origin master\n```\n\n# Passing the first stage\n\nThe entry point for your HTTP server implementation is in `src/main.rs`. Study\nand uncomment the relevant code, and push your changes to pass the first stage:\n\n```sh\ngit add .\ngit commit -m \"pass 1st stage\" # any msg\ngit push origin master\n```\n\nTime to move on to the next stage!\n\n# Stage 2 \u0026 beyond\n\nNote: This section is for stages 2 and beyond.\n\n1. Ensure you have `cargo (1.70)` installed locally\n1. Run `./your_server.sh` to run your program, which is implemented in\n   `src/main.rs`. This command compiles your Rust project, so it might be slow\n   the first time you run it. Subsequent runs will be fast.\n1. Commit your changes and run `git push origin master` to submit your solution\n   to CodeCrafters. Test output will be streamed to your terminal.\n\n\n# Functionalities implemented for each stage\n\nHere are the functionalities that you'll need to implement for each stage:\n\n## Stage 1: Bind to a port\n\nIn this stage, your task is to start a TCP server on port 4221.\n\n\n## Stage 2: Respond with 200\n\nIn this stage, you'll respond to a HTTP request with a 200 OK response.\n\nYour program will need to:\n\n- Accept a TCP connection\n- Read data from the connection (we'll get to parsing it in later stages)\n- Respond with `HTTP/1.1 200 OK\\r\\n\\r\\n` (there are two `\\r\\n`s at the end)\n   - `HTTP/1.1 200 OK` is the [HTTP Status Line](https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages#status_line).\n   - \\r\\n, also known as [CRLF](https://developer.mozilla.org/en-US/docs/Glossary/CRLF), is the end-of-line marker that HTTP uses.\n   - The first `\\r\\n` signifies the end of the status line.\n   - The second `\\r\\n` signifies the end of the response headers section (which is empty in this case).\n\nIt's okay to ignore the data received from the connection for now. We'll get to parsing it in later stages.\n\nFor more details on the structure of a HTTP response, view the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages#http_responses).\n\n\n## Stage 3: Respond with 404\n\nIn this stage, your program will need to extract the path from the HTTP request.\n\nHere's what the contents of a HTTP request look like:\n\n```\nGET /index.html HTTP/1.1\n\nHost: localhost:4221\nUser-Agent: curl/7.64.1\n```\n\n- `GET /index.html HTTP/1.1` is the [start line](https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages#start_line).\n   - `GET` is the [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods).\n   - `/index.html` is the [path](https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages#path).\n   - `HTTP/1.1` is the [HTTP version](https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages#http_versions).\n- `Host: localhost:4221` and `User-Agent: curl/7.64.1` are [HTTP headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages#headers).\n- Note that all of these lines are separated by `\\r\\n`, not just `\\n`.\n\nIn this stage, we'll only focus on extracting the path from the request.\n\nIf the path is `/`, you'll need to respond with a `200 OK `response. Otherwise, you'll need to respond with a `404 Not Found` response.\n\n\n## Stage 4: Respond with content\n\nIn this stage, your program will need to respond with a body. In the previous stages we were only sending a status code, no body.\n\nThe tester will send you a request of the form `GET /echo/\u003ca-random-string\u003e`.\n\nYour program will need to respond with a `200 OK` response. The response should have a content type of `text/plain`, and it should contain the random string as the body.\n\nAs an example, here's a request you might receive:\n\n```\nGET /echo/abc HTTP/1.1\n\nHost: localhost:4221\nUser-Agent: curl/7.64.1\n```\n\nAnd here's the response you're expected to send back:\n\n```\nHTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 3\n\nabc\n```\n\nRemember, lines in the response are separated by `\\r\\n`, not just `\\n`.\n\n\n## Stage 5: Parse headers\n\nIn this stage, your program will need to parse HTTP request headers.\n\nThe tester will send you a request of the form `GET /user-agent`, and it'll include a `User-Agent` header.\n\nYour program will need to respond with a `200 OK` response. The response should have a content type of `text/plain`, and it should contain the user agent value as the body.\n\nFor example, here's a request you might receive:\n\n```\nGET /user-agent HTTP/1.1\n\nHost: localhost:4221\nUser-Agent: curl/7.64.1\n```\n\nand here's the response you're expected to send back:\n\n```\nHTTP/1.1 200 OK\n\nContent-Type: text/plain\nContent-Length: 11\n\ncurl/7.64.1\n```\n\n\n## Stage 6: Concurrent connections\n\nUp until now, we've only tested your program against a single connection in each stage.\n\nIn this stage, your server will need to handle multiple concurrent connections.\n\nThe tester will send you multiple requests at the same time. Your server will need to respond to all of them.\n\n\n## Stage 7: Get a file\n\nIn this stage, your server will need to return the contents of a file.\n\nThe tester will execute your program with a `--directory` flag like this:\n\n```sh\n./your_server.sh --directory \u003cdirectory\u003e\n```\n\nIt'll then send you a request of the form `GET /files/\u003cfilename\u003e`.\n\nIf `\u003cfilename\u003e` exists in `\u003cdirectory\u003e`, you'll need to respond with a `200 OK` response. The response should have a content type of `application/octet-stream`, and it should contain the contents of the file as the body.\n\nIf the file doesn't exist, return a `404 Not Found` response.\n\n\n## Stage 8: Post a file\n\nIn this stage, your server will need to accept the contents of a file in a POST request and save it to a directory.\n\nJust like in the previous stage, the tester will execute your program with a `--directory` flag like this:\n\n```sh\n./your_server.sh --directory \u003cdirectory\u003e\n```\n\nIt'll then send you a request of the form `POST /files/\u003cfilename\u003e`. The request body will contain the contents of the file.\n\nYou'll need to fetch the contents of the file from the request body and save it to `\u003cdirectory\u003e/\u003cfilename\u003e`. The response code returned should be `201 Created`.\n\n\n# Extra functionalities added\n\n- Added mime types autodection for files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisuschrist%2Fcodecrafters-http-server-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyisuschrist%2Fcodecrafters-http-server-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisuschrist%2Fcodecrafters-http-server-rust/lists"}