Wrapping the async client in a blocking SyncClient facade.
Wrapping the async client in a blocking SyncClient facade.
#include <asio.hpp>
#include <iostream>
#include <string>
#include <utility>
class SyncClient {
public:
SyncClient() : http_(io_) {}
return run(http_.async_get(std::move(url), asio::use_future));
}
return run(
http_.async_post(std::move(url), std::move(body), asio::use_future));
}
private:
io_.restart();
io_.run();
return pending.get();
}
asio::io_context io_;
};
int main() {
SyncClient http;
http.post("https://postman-echo.com/post", R"({"qty": 1})");
std::cout << "post http " << b.
http_code_ <<
"\n";
}
long http_code_
Definition cofetch.h:176