https://github.com/maxrt101/http-server
HTTP Server
https://github.com/maxrt101/http-server
cpp17 http-server
Last synced: 10 months ago
JSON representation
HTTP Server
- Host: GitHub
- URL: https://github.com/maxrt101/http-server
- Owner: maxrt101
- Created: 2021-06-03T22:17:10.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-11-18T16:04:24.000Z (over 4 years ago)
- Last Synced: 2025-08-10T16:34:25.897Z (11 months ago)
- Topics: cpp17, http-server
- Language: C++
- Homepage:
- Size: 57.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HTTP Server
Simple HTTP Server implementation in C++.
Supports flask-like API for creating endpoints.
### How To Build:
Dependencies: `git`, `gcc`/`clang`, `make`, binutils(`ar`)
- Clone repo
- `cd http-server`
- `git submodule update --init --recursive`
- `make PREFIX=/path/to/install/dir`, set `PREFIX` to desired install location. If no prefix is specified, `build` folder will be created
After install `libhttpserver.a` and `libmrt.a` will be present inside `PREFIX/lib` along with all required headers (in `PREFIX/include`)
To embed http-server into your project, you can just include it as a git submodule, and run `make -C http-server` inside your projects `Makefile`
### Example:
```c++
mrt::Server server;
server.addEndpoint({"/api", http::Method::GET, [](auto request) {
return http::Response(http::OK).setContent("text/plain", "Hello, World!");
}});
server.addEndpoint({"/api", http::Method::POST, [](auto request) {
std::string body;
for (auto& p : request.header.params) {
body += p.first + " = " + p.second + "\n";
}
return http::Response(http::OK).setContent("text/plain", body);
}});
server.run();
```