Kurlyk
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
10int 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;
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
35 return 0;
36}
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.
Injects an Authorization: Bearer <token> header.
bool authorize(HttpRequest &request) const override
Modifies an HttpRequest in-place to include authentication credentials.
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
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.
utils::CaseInsensitiveMultimap QueryParams
Alias for query parameters in HTTP requests, stored case-insensitively.
#define KURLYK_PRINT
int main()
Minimal example showing BearerTokenAuthProvider without OAuth/hmac-cpp.