Skip to content

Commit cf0f164

Browse files
committed
update readme.md with new http client info and short fixes
1 parent 112fc2b commit cf0f164

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ You can just add this repo as a git submodule, which at this point is
1919
probably (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

2727
Alternatively, you can run the examples and tests like you would any other CMake based
2828
project:
@@ -33,10 +33,11 @@ cmake --build build
3333

3434
There 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
5859
response. 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

6265
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",
163166
if (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
```

examples/http_client.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ void exit_handler(int s){
1414
int main(int argc, char** argv)
1515
{
1616
netlib::http::http_client client;
17-
1817
auto res = client.get("http://example.com");
1918

2019
if (res.second) {

0 commit comments

Comments
 (0)