64 :
url(std::move(url_)) {}
67 :
url(std::move(url_)),
method(std::move(method_)) {}
70 :
url(std::move(url_))
71 ,
method(std::move(method_))
72 ,
headers(std::move(headers_)) {}
77 std::vector<uint8_t> body_)
78 :
url(std::move(url_))
79 ,
method(std::move(method_))
81 ,
body(std::move(body_)) {}
89 headers[
"Content-Type"] = content_type;
99 headers[
"Authorization"] = auth;
109 body.assign(str.begin(), str.end());
168 return std::string(
body.begin(),
body.end());
177 const std::string& name)
const {
233 return "IHttpClient";
247 return ::kcenon::common::make_error<http_response>(
249 "HTTP client not available",
258 return "null_http_client";
287 std::chrono::milliseconds timeout = std::chrono::milliseconds{30000}) = 0;
Result type for error handling with member function support.
Interface for modules that provide HTTP client implementations.
virtual ~IHttpClientProvider()=default
virtual std::shared_ptr< IHttpClient > get_http_client()=0
Get the default HTTP client instance.
virtual std::shared_ptr< IHttpClient > create_http_client(std::chrono::milliseconds timeout=std::chrono::milliseconds{30000})=0
Create a new HTTP client with specific configuration.
Abstract interface for HTTP client implementations.
virtual ~IHttpClient()=default
virtual bool is_available() const =0
Check if the HTTP client is available and properly configured.
virtual ::kcenon::common::Result< http_response > send(const http_request &request)=0
Send an HTTP request synchronously.
virtual std::string get_implementation_name() const
Get the implementation name for logging/debugging.
Null implementation for when HTTP transport is disabled.
bool is_available() const override
Check if the HTTP client is available and properly configured.
std::string get_implementation_name() const override
Get the implementation name for logging/debugging.
::kcenon::common::Result< http_response > send(const http_request &) override
Send an HTTP request synchronously.
constexpr int NOT_INITIALIZED
std::function< std::shared_ptr< IHttpClient >()> HttpClientFactory
Factory function type for creating HTTP client instances.
std::map< std::string, std::string > http_headers
HTTP headers container type.
Umbrella header for Result<T> type and related utilities.
Represents an HTTP request.
http_request(std::string url_)
http_request & set_authorization(const std::string &auth)
Set Authorization header.
bool follow_redirects
Whether to follow redirects (default: true)
http_headers headers
Request headers.
http_request & set_body(const std::string &str)
Set body from string.
http_request(std::string url_, std::string method_, http_headers headers_, std::vector< uint8_t > body_)
std::vector< uint8_t > body
Request body (for POST, PUT, PATCH)
http_request & set_content_type(const std::string &content_type)
Set Content-Type header.
int max_redirects
Maximum number of redirects to follow (default: 5)
std::chrono::milliseconds timeout
Request timeout (default: 30 seconds)
std::string url
Request URL (must include scheme, e.g., "https://api.example.com/v1/data")
http_request(std::string url_, std::string method_, http_headers headers_)
http_request(std::string url_, std::string method_)
std::string method
HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
Represents an HTTP response.
bool is_server_error() const
Check if response indicates server error (5xx status)
bool is_success() const
Check if response indicates success (2xx status)
http_headers headers
Response headers.
std::string body_as_string() const
Get body as string.
std::optional< std::string > final_url
Final URL after redirects (may differ from request URL)
std::chrono::milliseconds elapsed
Time taken to receive the response.
std::vector< uint8_t > body
Response body.
bool is_client_error() const
Check if response indicates client error (4xx status)
int status_code
HTTP status code (e.g., 200, 404, 500)
std::optional< std::string > get_header(const std::string &name) const
Get a specific header value.
std::string reason_phrase
Status reason phrase (e.g., "OK", "Not Found")