cofetch
Chainable, high-performance async HTTP client for C++ event loops
Loading...
Searching...
No Matches
example_future.cpp
std::future
style: start the request, drive the loop,
get()
.
std::future
style: start the request, drive the loop,
get()
.
// std::future style: start the request, drive the loop, collect the
// result. get() rethrows transport errors as std::system_error.
#include <
cofetch.h
>
#include <asio.hpp>
#include <iostream>
int
main() {
asio::io_context io;
cofetch::Client
http(io);
auto
pending =
http.
async_get
(
"https://postman-echo.com/get"
, asio::use_future);
io.run();
// the future is ready once the loop drains
const
cofetch::Response
res = pending.get();
std::cout <<
"http "
<< res.
http_code_
<<
"\n"
;
}
cofetch::Client
Definition
cofetch.h:266
cofetch::Client::async_get
auto async_get(std::string url, CompletionToken &&token)
Definition
cofetch.h:324
cofetch::Response
Definition
cofetch.h:111
cofetch::Response::http_code_
long http_code_
Definition
cofetch.h:176
cofetch.h
Generated by
1.9.8