https://github.com/edenreich/http-component
An easy to use native component for interacting with the http layer written in C++
https://github.com/edenreich/http-component
cmake cpp cpp-component cpp17 http http-client http-server request-handler response-parsing unix-socket winsock2
Last synced: 3 months ago
JSON representation
An easy to use native component for interacting with the http layer written in C++
- Host: GitHub
- URL: https://github.com/edenreich/http-component
- Owner: edenreich
- License: mit
- Created: 2019-09-15T10:48:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-07T22:53:49.000Z (over 5 years ago)
- Last Synced: 2025-01-16T16:42:58.804Z (5 months ago)
- Topics: cmake, cpp, cpp-component, cpp17, http, http-client, http-server, request-handler, response-parsing, unix-socket, winsock2
- Language: C++
- Homepage:
- Size: 135 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP Component
An easy to use component for interacting with the http layer written in C++
## Usage
```cpp
// main.cpp
#include
#include
#include
#include#include
using namespace Http;
int main(int argc, char const *argv[])
{
Server server;server.bind("0.0.0.0");
server.listen(8080);
server.onConnection([](Interfaces::ClientInterface * client) {
Interfaces::MessageInterface * requestMessage = client->getRequest()->getMessage();
std::stringstream responseMessage;std::string json = R"JSON(
[
{
"id": 1,
"name": "Pizza",
"description": "lorem ipsum"
},
{
"id": 2,
"name": "Cola",
"description": "lorem ipsum"
},
{
"id": 3,
"name": "Hamburger",
"description": "lorem ipsum"
}
]
)JSON";responseMessage << "HTTP/1.1 200 OK\r\n";
responseMessage << "Content-Type: application/json\r\n";
responseMessage << "Content-Length: " << json.length() << "\r\n";
responseMessage << "Connection: close\r\n";
responseMessage << "\r\n";
responseMessage << "\r\n";
responseMessage << json;return new Response(new Message(responseMessage));
});return 0;
}
```## Target
This project targets Linux, Windows and macOS