coeurl.cpp 1.1 KB

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