| 1 | #include <thread> |
| 2 | |
| 3 | #include "coeurl/client.hpp" |
| 4 | #include "coeurl/request.hpp" |
| 5 | |
| 6 | #include "spdlog/sinks/stdout_color_sinks.h" |
| 7 | |
| 8 | int main(int, char **) { |
| 9 | auto logger = spdlog::stdout_color_mt("coeurl"); |
| 10 | logger->set_level(spdlog::level::trace); |
| 11 | coeurl::Client::set_logger(logger); |
| 12 | |
| 13 | coeurl::Client g{}; |
| 14 | |
| 15 | std::thread t([&g, &logger]() { |
| 16 | std::this_thread::sleep_for(std::chrono::seconds(1)); |
| 17 | for (int i = 0; i < 10; i++) |
| 18 | g.get("http://localhost:5000/", [](const coeurl::Request &) {}); |
| 19 | |
| 20 | std::this_thread::sleep_for(std::chrono::seconds(1)); |
| 21 | for (int i = 0; i < 10; i++) |
| 22 | g.get("http://localhost:5000/", [&logger](const coeurl::Request &r) { |
| 23 | for (const auto &[k, v] : r.response_headers()) |
| 24 | logger->info("Header: {}: {}", k, v); |
| 25 | }); |
| 26 | |
| 27 | auto r = std::make_shared<coeurl::Request>(&g, coeurl::Request::Method::Post, "http://localhost:5000/post"); |
| 28 | r->request("ABCD"); |
| 29 | r->on_complete([](const coeurl::Request &) {}); |
| 30 | g.submit_request(r); |
| 31 | }); |
| 32 | |
| 33 | t.join(); |
| 34 | |
| 35 | return 0; |
| 36 | } |