@@ -19,10 +19,10 @@ You can just add this repo as a git submodule, which at this point is
19
19
probably (IMO) the best way to handle C++ dependencies.
20
20
21
21
``` 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
23
23
```
24
24
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.
26
26
27
27
Alternatively, you can run the examples and tests like you would any other CMake based
28
28
project:
@@ -33,10 +33,11 @@ cmake --build build
33
33
34
34
There are some cmake flags you can use:
35
35
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 |
40
41
41
42
### Short introduction
42
43
@@ -57,6 +58,8 @@ if you like.
57
58
` netlib::server_response ` is a struct that you can return in your server callbacks, which instructs the server how to handle your
58
59
response. You can pass it some data to relay to clients, or instruct server to terminate the connection (after sending data, if any).
59
60
61
+ ` netlib::http::client ` is an HTTP client, which can currently only GET http responses (No other Verbs, and no TLS).
62
+
60
63
### Examples
61
64
62
65
In 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",
163
166
if (server_create_res) {
164
167
std::cerr << "Error initializing server: " << server_create_res.message() << std::endl;
165
168
}
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;
166
190
```
0 commit comments