Kurlyk
Toggle main menu visibility
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
5
void
print_response
(
const
kurlyk::HttpResponsePtr
& response) {
6
KURLYK_PRINT
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
15
int
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();
33
kurlyk::deinit
();
34
return
0;
35
}
kurlyk::HttpClient
Concrete HTTP client for making requests to a specific host.
Definition
HttpClient.hpp:17
kurlyk::HttpClient::get
bool get(const std::string &path, const QueryParams &query, const Headers &headers, HttpResponseCallback callback)
Sends a GET request.
Definition
HttpClient.hpp:681
kurlyk.hpp
Main header file for the Kurlyk library, providing HTTP and WebSocket support.
kurlyk::init
void init(const bool use_async=true)
Initializes the Kurlyk library, setting up necessary managers and the network worker.
Definition
runtime.hpp:13
kurlyk::HttpResponsePtr
std::unique_ptr< HttpResponse > HttpResponsePtr
Owning pointer to an HTTP response.
Definition
HttpResponse.hpp:36
kurlyk::deinit
void deinit()
Deinitializes the Kurlyk library, stopping async processing or cleaning up synchronous state.
Definition
runtime.hpp:26
kurlyk::Headers
utils::CaseInsensitiveMultimap Headers
Alias for HTTP headers, providing a case-insensitive unordered multimap.
Definition
CaseInsensitiveMultimap.hpp:62
kurlyk::http_get
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
kurlyk::QueryParams
utils::CaseInsensitiveMultimap QueryParams
Alias for query parameters in HTTP requests, stored case-insensitively.
Definition
CaseInsensitiveMultimap.hpp:65
KURLYK_PRINT
#define KURLYK_PRINT
Definition
print_utils.hpp:8
print_response
void print_response(const kurlyk::HttpResponsePtr &response)
Definition
simple_http_request_example.cpp:5
main
int main()
Definition
simple_http_request_example.cpp:15
examples
simple_http_request_example.cpp
Generated by
1.17.0