Kurlyk
Toggle main menu visibility
Loading...
Searching...
No Matches
simple_bearer_auth_example.cpp
Go to the documentation of this file.
1
#define KURLYK_AUTO_INIT 0
2
#ifndef KURLYK_OAUTH_SUPPORT
3
# define KURLYK_OAUTH_SUPPORT 0
4
#endif
5
#include <
kurlyk.hpp
>
6
#include <iostream>
7
10
int
main
() {
11
kurlyk::init
(
true
);
12
13
// Replace with your actual token or load from environment.
14
const
std::string token =
"YOUR_BEARER_TOKEN"
;
15
16
kurlyk::HttpClient
client(
"https://api.example.com"
);
17
18
kurlyk::Headers
headers;
19
kurlyk::http::auth::BearerTokenAuthProvider
auth(token);
20
auth.
authorize
(headers);
21
22
auto
future = client.
get
(
"/resource"
,
kurlyk::QueryParams
(), headers);
23
24
auto
response = future.get();
25
if
(response && response->ready) {
26
KURLYK_PRINT
<<
"Status: "
<< response->status_code << std::endl;
27
KURLYK_PRINT
<<
"Body: "
<< response->content << std::endl;
28
}
else
{
29
KURLYK_PRINT
<<
"Request failed: "
30
<< (response ? response->error_code.message() :
"null"
)
31
<< std::endl;
32
}
33
34
kurlyk::deinit
();
35
return
0;
36
}
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::http::auth::BearerTokenAuthProvider
Injects an Authorization: Bearer <token> header.
Definition
BearerTokenAuthProvider.hpp:17
kurlyk::http::auth::BearerTokenAuthProvider::authorize
bool authorize(HttpRequest &request) const override
Modifies an HttpRequest in-place to include authentication credentials.
Definition
BearerTokenAuthProvider.hpp:30
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::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::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
main
int main()
Minimal example showing BearerTokenAuthProvider without OAuth/hmac-cpp.
Definition
simple_bearer_auth_example.cpp:10
examples
simple_bearer_auth_example.cpp
Generated by
1.17.0