34 std::cout <<
"=== Simple HTTP Client Demo ===" << std::endl;
37 auto client = std::make_shared<core::http_client>(std::chrono::seconds(30));
40 std::this_thread::sleep_for(std::chrono::milliseconds(500));
43 std::cout <<
"\n1. GET request to /" << std::endl;
44 std::cout << std::string(50,
'-') << std::endl;
46 auto response1 = client->get(
"http://localhost:8080/");
47 if (response1.is_ok())
53 std::cerr <<
"Request failed: " << response1.error().message << std::endl;
57 std::cout <<
"\n2. GET request with query parameters" << std::endl;
58 std::cout << std::string(50,
'-') << std::endl;
60 std::map<std::string, std::string> query_params = {
64 auto response2 = client->get(
"http://localhost:8080/api/hello", query_params);
65 if (response2.is_ok())
71 std::cerr <<
"Request failed: " << response2.error().message << std::endl;
75 std::cout <<
"\n3. GET request with path parameter" << std::endl;
76 std::cout << std::string(50,
'-') << std::endl;
78 auto response3 = client->get(
"http://localhost:8080/users/42");
79 if (response3.is_ok())
85 std::cerr <<
"Request failed: " << response3.error().message << std::endl;
89 std::cout <<
"\n4. POST request" << std::endl;
90 std::cout << std::string(50,
'-') << std::endl;
92 std::string post_body =
"Hello from HTTP client!";
93 auto response4 = client->post(
"http://localhost:8080/api/echo", post_body);
94 if (response4.is_ok())
100 std::cerr <<
"Request failed: " << response4.error().message << std::endl;
104 std::cout <<
"\n5. Testing 404 Not Found" << std::endl;
105 std::cout << std::string(50,
'-') << std::endl;
107 auto response5 = client->get(
"http://localhost:8080/nonexistent");
108 if (response5.is_ok())
114 std::cerr <<
"Request failed: " << response5.error().message << std::endl;
117 std::cout <<
"\n=== Demo complete ===" << std::endl;