Kurlyk
Loading...
Searching...
No Matches
simple_http_request_example.cpp
Go to the documentation of this file.
1#include <iostream>
2#define KURLYK_AUTO_INIT 0
3#include <kurlyk.hpp>
4
7 << "ready: " << response->ready << std::endl
8 << "response: " << std::endl
9 << response->content << std::endl
10 << "error_code: " << response->error_code << std::endl
11 << "status_code: " << response->status_code << std::endl
12 << "----------------------------------------" << std::endl;
13}
14
15int main() {
16 kurlyk::init(true);
17 kurlyk::HttpClient client("https://httpbin.org");
18
19 KURLYK_PRINT << "Sending GET request using HttpClient method..." << std::endl;
20 client.get("/ip", kurlyk::QueryParams(), kurlyk::Headers(),
21 [](const kurlyk::HttpResponsePtr response) {
22 print_response(response);
23 });
24
25 KURLYK_PRINT << "Sending GET request using standalone function..." << std::endl;
26 kurlyk::http_get("https://httpbin.org/ip", kurlyk::QueryParams(), kurlyk::Headers(),
27 [](const kurlyk::HttpResponsePtr response) {
28 print_response(response);
29 });
30
31 KURLYK_PRINT << "Press Enter to exit..." << std::endl;
32 std::cin.get();
34 return 0;
35}
Concrete HTTP client for making requests to a specific host.
bool get(const std::string &path, const QueryParams &query, const Headers &headers, HttpResponseCallback callback)
Sends a GET request.
Main header file for the Kurlyk library, providing HTTP and WebSocket support.
void init(const bool use_async=true)
Initializes the Kurlyk library, setting up necessary managers and the network worker.
Definition runtime.hpp:13
std::unique_ptr< HttpResponse > HttpResponsePtr
Owning pointer to an HTTP response.
void deinit()
Deinitializes the Kurlyk library, stopping async processing or cleaning up synchronous state.
Definition runtime.hpp:26
utils::CaseInsensitiveMultimap Headers
Alias for HTTP headers, providing a case-insensitive unordered multimap.
uint64_t http_get(const std::string &url, const QueryParams &query, const Headers &headers, HttpResponseCallback callback)
Sends an asynchronous HTTP GET request with a callback.
Definition utils.hpp:421
utils::CaseInsensitiveMultimap QueryParams
Alias for query parameters in HTTP requests, stored case-insensitively.
#define KURLYK_PRINT
void print_response(const kurlyk::HttpResponsePtr &response)