https://github.com/pascalpost/codecrafters-http-server-cpp
https://github.com/pascalpost/codecrafters-http-server-cpp
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/pascalpost/codecrafters-http-server-cpp
- Owner: pascalPost
- Created: 2024-06-30T06:40:01.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-14T11:09:43.000Z (almost 2 years ago)
- Last Synced: 2025-01-25T22:39:32.491Z (over 1 year ago)
- Language: C++
- Size: 86.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)
This is a starting point for C++ solutions to the
["Build Your Own HTTP server" Challenge](https://app.codecrafters.io/courses/http-server/overview).
**Note**: If you're viewing this repo on GitHub, head over to
[codecrafters.io](https://codecrafters.io) to try the challenge.
# http-server-cpp
This repo contains my C++ style implementation of a http server to parse the codecrafters
challenge. The focus is not to pass the tests with minimal effort, but to provide a solution
in the spirit of C++ (at least my understanding of it :wink:).
The features are:
- allows to easily specify endpoints for the server:
```cpp
server.add_endpoint("/", [](const auto &) -> std::string { return "HTTP/1.1 200 OK\r\n\r\n"; });
```
- url patten matching: `/echo/{str}` will match `/echo/abc` and provide a mapping of `str`
to `abc`, e.g.:
```cpp
server.add_endpoint("/echo/{str}", [](const auto &matches) -> std::string {
const std::string str = matches.at("str");
return std::format("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: {}\r\n\r\n{}", str.size(),
str);
});
```