Thin HTTP Client wrapper for internal use.
More...
#include <http_client.h>
|
| struct | Response |
| | Normalized response returned by the wrapper functions. More...
|
|
| using | WriteCallback = std::function<bool(const std::string_view&)> |
| | Callback type for streaming response body data.
|
|
| | HTTPClient (const std::string &url) |
| | Construct a Persistent HTTPClient.
|
|
| HTTPClient (const HTTPClient &)=delete |
|
HTTPClient & | operator= (const HTTPClient &)=delete |
| | HTTPClient (HTTPClient &&)=default |
| | Move constructor for HTTPClient object.
|
| HTTPClient & | operator= (HTTPClient &&)=default |
| | Move assignment operator for HTTPClient object.
|
| Response | Get (const std::string &url, const std::map< std::string, std::string > &headers={}, int timeout_ms=30000) |
| | Instance GET (Persistent).
|
| Response | Post (const std::string &url, const std::map< std::string, std::string > &headers, const std::string &body, int timeout_ms=30000, WriteCallback write_cb=nullptr, const std::vector< httplib::MultipartFormData > &multipart={}) |
| | Instance POST (Persistent).
|
|
| static Response | post (const std::string &url, const std::map< std::string, std::string > &headers, const std::string &body, int timeout_ms=30000, WriteCallback write_cb=nullptr, const std::vector< httplib::MultipartFormData > &multipart={}) |
| | Static POST (Transient).
|
| static Response | get (const std::string &url, const std::map< std::string, std::string > &headers, int timeout_ms=30000) |
| | Static GET (Transient).
|
| static Response | get (const std::string &url, const httplib::Params ¶ms, const std::map< std::string, std::string > &headers, int timeout_ms=30000) |
| | Static GET with query parameters (Transient).
|
Thin HTTP Client wrapper for internal use.
Usage contract:
- Callers receive an HTTPClient::Response and should inspect response.error and response.status_code to decide success.
- For streaming responses provide a WriteCallback to post() to receive incremental body chunks.
◆ WriteCallback
Callback type for streaming response body data.
The callback receives a string_view containing the next chunk of response body data. It should return true to continue receiving data or false to abort the transfer.
◆ HTTPClient() [1/2]
| agents::HTTPClient::HTTPClient |
( |
const std::string & | url | ) |
|
|
inlineexplicit |
Construct a Persistent HTTPClient.
- Establishes the base connection context. The TCP connection is maintained alive where possible (Keep-Alive).
◆ HTTPClient() [2/2]
| agents::HTTPClient::HTTPClient |
( |
HTTPClient && | | ) |
|
|
default |
Move constructor for HTTPClient object.
- Parameters
-
◆ Get()
| Response agents::HTTPClient::Get |
( |
const std::string & | url, |
|
|
const std::map< std::string, std::string > & | headers = {}, |
|
|
int | timeout_ms = 30000 ) |
|
inline |
Instance GET (Persistent).
- Parameters
-
| url | The URL to GET |
| headers | The headers to include |
| timeout_ms | The timeout in milliseconds |
◆ get() [1/2]
| Response agents::HTTPClient::get |
( |
const std::string & | url, |
|
|
const httplib::Params & | params, |
|
|
const std::map< std::string, std::string > & | headers, |
|
|
int | timeout_ms = 30000 ) |
|
inlinestatic |
Static GET with query parameters (Transient).
- Parameters
-
| url | The URL to GET |
| params | The query parameters |
| headers | The headers to include |
| timeout_ms | The timeout in milliseconds |
- Returns
- Response The HTTP response
◆ get() [2/2]
| Response agents::HTTPClient::get |
( |
const std::string & | url, |
|
|
const std::map< std::string, std::string > & | headers, |
|
|
int | timeout_ms = 30000 ) |
|
inlinestatic |
Static GET (Transient).
- Parameters
-
| url | The URL to GET |
| headers | The headers to include |
| timeout_ms | The timeout in milliseconds |
- Returns
- Response The HTTP response
◆ operator=()
Move assignment operator for HTTPClient object.
- Parameters
-
◆ Post()
| Response agents::HTTPClient::Post |
( |
const std::string & | url, |
|
|
const std::map< std::string, std::string > & | headers, |
|
|
const std::string & | body, |
|
|
int | timeout_ms = 30000, |
|
|
WriteCallback | write_cb = nullptr, |
|
|
const std::vector< httplib::MultipartFormData > & | multipart = {} ) |
|
inline |
Instance POST (Persistent).
- Parameters
-
| url | The URL to POST to |
| headers | The headers to include |
| body | The body to include |
| timeout_ms | The timeout in milliseconds |
| write_cb | Optional streaming write callback |
| multipart | Optional multipart form data |
◆ post()
| Response agents::HTTPClient::post |
( |
const std::string & | url, |
|
|
const std::map< std::string, std::string > & | headers, |
|
|
const std::string & | body, |
|
|
int | timeout_ms = 30000, |
|
|
WriteCallback | write_cb = nullptr, |
|
|
const std::vector< httplib::MultipartFormData > & | multipart = {} ) |
|
inlinestatic |
Static POST (Transient).
- Parameters
-
| url | The URL to POST to |
| headers | The headers to include |
| body | The body to include |
| timeout_ms | The timeout in milliseconds |
| write_cb | Optional streaming write callback |
| multipart | Optional multipart form data |
- Returns
- Response The HTTP response