Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::interfaces::http_request Struct Reference

Represents an HTTP request. More...

#include <http_client_interface.h>

Collaboration diagram for kcenon::common::interfaces::http_request:
Collaboration graph

Public Member Functions

 http_request ()=default
 
 http_request (std::string url_)
 
 http_request (std::string url_, std::string method_)
 
 http_request (std::string url_, std::string method_, http_headers headers_)
 
 http_request (std::string url_, std::string method_, http_headers headers_, std::vector< uint8_t > body_)
 
http_requestset_content_type (const std::string &content_type)
 Set Content-Type header.
 
http_requestset_authorization (const std::string &auth)
 Set Authorization header.
 
http_requestset_body (const std::string &str)
 Set body from string.
 

Public Attributes

std::string url
 Request URL (must include scheme, e.g., "https://api.example.com/v1/data")
 
std::string method = "GET"
 HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
 
http_headers headers
 Request headers.
 
std::vector< uint8_t > body
 Request body (for POST, PUT, PATCH)
 
std::chrono::milliseconds timeout {30000}
 Request timeout (default: 30 seconds)
 
bool follow_redirects = true
 Whether to follow redirects (default: true)
 
int max_redirects = 5
 Maximum number of redirects to follow (default: 5)
 

Detailed Description

Represents an HTTP request.

Definition at line 37 of file http_client_interface.h.

Constructor & Destructor Documentation

◆ http_request() [1/5]

kcenon::common::interfaces::http_request::http_request ( )
default

◆ http_request() [2/5]

kcenon::common::interfaces::http_request::http_request ( std::string url_)
inlineexplicit

Definition at line 63 of file http_client_interface.h.

64 : url(std::move(url_)) {}
std::string url
Request URL (must include scheme, e.g., "https://api.example.com/v1/data")

◆ http_request() [3/5]

kcenon::common::interfaces::http_request::http_request ( std::string url_,
std::string method_ )
inline

Definition at line 66 of file http_client_interface.h.

67 : url(std::move(url_)), method(std::move(method_)) {}
std::string method
HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)

◆ http_request() [4/5]

kcenon::common::interfaces::http_request::http_request ( std::string url_,
std::string method_,
http_headers headers_ )
inline

Definition at line 69 of file http_client_interface.h.

70 : url(std::move(url_))
71 , method(std::move(method_))
72 , headers(std::move(headers_)) {}

◆ http_request() [5/5]

kcenon::common::interfaces::http_request::http_request ( std::string url_,
std::string method_,
http_headers headers_,
std::vector< uint8_t > body_ )
inline

Definition at line 74 of file http_client_interface.h.

78 : url(std::move(url_))
79 , method(std::move(method_))
80 , headers(std::move(headers_))
81 , body(std::move(body_)) {}
std::vector< uint8_t > body
Request body (for POST, PUT, PATCH)

Member Function Documentation

◆ set_authorization()

http_request & kcenon::common::interfaces::http_request::set_authorization ( const std::string & auth)
inline

Set Authorization header.

Parameters
authAuthorization value (e.g., "Bearer token123")
Returns
Reference to this for chaining

Definition at line 98 of file http_client_interface.h.

98 {
99 headers["Authorization"] = auth;
100 return *this;
101 }

References headers.

◆ set_body()

http_request & kcenon::common::interfaces::http_request::set_body ( const std::string & str)
inline

Set body from string.

Parameters
strString body content
Returns
Reference to this for chaining

Definition at line 108 of file http_client_interface.h.

108 {
109 body.assign(str.begin(), str.end());
110 return *this;
111 }

References body.

◆ set_content_type()

http_request & kcenon::common::interfaces::http_request::set_content_type ( const std::string & content_type)
inline

Set Content-Type header.

Parameters
content_typeMIME type string
Returns
Reference to this for chaining

Definition at line 88 of file http_client_interface.h.

88 {
89 headers["Content-Type"] = content_type;
90 return *this;
91 }

References headers.

Member Data Documentation

◆ body

std::vector<uint8_t> kcenon::common::interfaces::http_request::body

Request body (for POST, PUT, PATCH)

Definition at line 48 of file http_client_interface.h.

Referenced by set_body().

◆ follow_redirects

bool kcenon::common::interfaces::http_request::follow_redirects = true

Whether to follow redirects (default: true)

Definition at line 54 of file http_client_interface.h.

◆ headers

http_headers kcenon::common::interfaces::http_request::headers

Request headers.

Definition at line 45 of file http_client_interface.h.

Referenced by set_authorization(), and set_content_type().

◆ max_redirects

int kcenon::common::interfaces::http_request::max_redirects = 5

Maximum number of redirects to follow (default: 5)

Definition at line 57 of file http_client_interface.h.

◆ method

std::string kcenon::common::interfaces::http_request::method = "GET"

HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)

Definition at line 42 of file http_client_interface.h.

◆ timeout

std::chrono::milliseconds kcenon::common::interfaces::http_request::timeout {30000}

Request timeout (default: 30 seconds)

Definition at line 51 of file http_client_interface.h.

51{30000};

◆ url

std::string kcenon::common::interfaces::http_request::url

Request URL (must include scheme, e.g., "https://api.example.com/v1/data")

Definition at line 39 of file http_client_interface.h.


The documentation for this struct was generated from the following file: