Kurlyk
Loading...
Searching...
No Matches
simple_http_request_example.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <kurlyk.hpp>
3
6 << "ready: " << response->ready << std::endl
7 << "response: " << std::endl
8 << response->content << std::endl
9 << "error_code: " << response->error_code << std::endl
10 << "status_code: " << response->status_code << std::endl
11 << "----------------------------------------" << std::endl;
12}
13
14int main() {
15 kurlyk::HttpClient client("https://httpbin.org");
16
17 KURLYK_PRINT << "Sending GET request using HttpClient method..." << std::endl;
18 client.get("/ip", kurlyk::QueryParams(), kurlyk::Headers(),
19 [](const kurlyk::HttpResponsePtr response) {
20 print_response(response);
21 });
22
23 KURLYK_PRINT << "Sending GET request using standalone function..." << std::endl;
24 kurlyk::http_get("https://httpbin.org/ip", kurlyk::QueryParams(), kurlyk::Headers(),
25 [](const kurlyk::HttpResponsePtr response) {
26 print_response(response);
27 });
28
29 KURLYK_PRINT << "Press Enter to exit..." << std::endl;
30 std::cin.get();
32 return 0;
33}
A client class for making HTTP 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.
std::unique_ptr< HttpResponse > HttpResponsePtr
A unique pointer to an HttpResponse object for memory management.
void deinit()
Deinitializes the Kurlyk library, stopping the network worker and releasing resources.
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:260
utils::CaseInsensitiveMultimap QueryParams
Alias for query parameters in HTTP requests, stored case-insensitively.
#define KURLYK_PRINT
void print_response(const kurlyk::HttpResponsePtr &response)