@@ -19,10 +19,10 @@ You can just add this repo as a git submodule, which at this point is
1919probably (IMO) the best way to handle C++ dependencies.
2020
2121``` shell
22- git submodule add https://github.com/lpcvoid/cpp-net-lib.git extern/cpp-net-lib
22+ git submodule add https://github.com/lpcvoid/cpp-net-lib.git extern
2323```
2424
25- This will check out the lib as a submodule within your project. Now just ` #include "extern/netlib.hpp" ` somewhere.
25+ This will check out the lib as a submodule within your project. Now just ` #include "extern/cpp-net-lib/src/ netlib.hpp" ` somewhere.
2626
2727Alternatively, you can run the examples and tests like you would any other CMake based
2828project:
@@ -33,10 +33,11 @@ cmake --build build
3333
3434There are some cmake flags you can use:
3535
36- | Option | Default | Description |
37- | ---| ---| ---|
38- | __ BUILD_TESTS__ | __ ON__ | Builds tests using ` doctest ` ,which is then introduced as a dependency. |
39- | __ BUILD_EXAMPLES__ | __ ON__ | Builds some small example programs. |
36+ | Option | Default | Description |
37+ | --------------------| ----------| -----------------------------------------------------------------------------------|
38+ | __ BUILD_TESTS__ | __ ON__ | Builds tests using ` doctest ` ,which is then introduced as a dependency. |
39+ | __ BUILD_EXAMPLES__ | __ ON__ | Builds some small example programs. |
40+ | __ WITH_HTTP__ | __ ON__ | Builds library with HTTP support |
4041
4142### Short introduction
4243
@@ -57,6 +58,8 @@ if you like.
5758` netlib::server_response ` is a struct that you can return in your server callbacks, which instructs the server how to handle your
5859response. You can pass it some data to relay to clients, or instruct server to terminate the connection (after sending data, if any).
5960
61+ ` netlib::http::client ` is an HTTP client, which can currently only GET http responses (No other Verbs, and no TLS).
62+
6063### Examples
6164
6265In all of these examples, I assume you have ` using namespace std::chrono_literals `
@@ -163,4 +166,25 @@ std::error_condition server_create_res = server.create("localhost",
163166if (server_create_res) {
164167 std::cerr << "Error initializing server: " << server_create_res.message() << std::endl;
165168}
169+ ```
170+
171+ #### HTTP client (GET request)
172+
173+ ``` C++
174+ netlib::http::http_client client;
175+ auto res = client.get(" http://example.com" );
176+
177+ if (res.second) {
178+ std::cerr << "Error: " << res.second.message() << std::endl;
179+ exit (1);
180+ }
181+
182+ std::cout << " Got HTTP response: " << res.first->response_code <<
183+ " , version " << res.first->version.first << " ." << res.first->version.second << std::endl;
184+ std::cout << " Header entries:" << std::endl;
185+ std::for_each (res.first->headers.begin(), res.first->headers.end(), [ ] (auto header_entry) {
186+ std::cout << header_entry.first << " = " << header_entry.second << std::endl;
187+ });
188+ std::cout << "Body:" << std::endl;
189+ std::cout << res.first.value().body << std::endl;
166190```
0 commit comments