cofetch
Chainable, high-performance async HTTP client for C++ event loops
Loading...
Searching...
No Matches
example_hello.cpp

The smallest cofetch program: one GET, one callback.

The smallest cofetch program: one GET, one callback.

// The smallest cofetch program: one GET, one callback.
#include <cofetch.h>
#include <asio.hpp>
#include <iostream>
int main() {
asio::io_context io;
cofetch::Client http(io);
http.async_get("https://postman-echo.com/get",
[](std::error_code ec, const cofetch::Response& res) {
if (ec) {
std::cerr << "transport error: " << ec.message() << "\n";
return;
}
std::cout << "http " << res.http_code_ << "\n"
<< res.data_ << "\n";
});
io.run(); // returns once nothing is left to do
}
Definition cofetch.h:266
auto async_get(std::string url, CompletionToken &&token)
Definition cofetch.h:324
Definition cofetch.h:111
long http_code_
Definition cofetch.h:176
std::string data_
Definition cofetch.h:177