Agents 1.4.0
Edge AI Agents SDK
Loading...
Searching...
No Matches
agents::HTTPClient Class Reference

Thin HTTP Client wrapper for internal use. More...

#include <http_client.h>

Classes

struct  Response
 Normalized response returned by the wrapper functions. More...

Public Types

using WriteCallback = std::function<bool(const std::string_view&)>
 Callback type for streaming response body data.

Public Member Functions

 HTTPClient (const std::string &url)
 Construct a Persistent HTTPClient.
 HTTPClient (const HTTPClient &)=delete
HTTPClientoperator= (const HTTPClient &)=delete
 HTTPClient (HTTPClient &&)=default
 Move constructor for HTTPClient object.
HTTPClientoperator= (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 Public Member Functions

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 &params, const std::map< std::string, std::string > &headers, int timeout_ms=30000)
 Static GET with query parameters (Transient).

Detailed Description

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.

Member Typedef Documentation

◆ WriteCallback

using agents::HTTPClient::WriteCallback = std::function<bool(const std::string_view&)>

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.

Constructor & Destructor Documentation

◆ 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
otherThe other HTTPClient to move from

Member Function Documentation

◆ 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
urlThe URL to GET
headersThe headers to include
timeout_msThe 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
urlThe URL to GET
paramsThe query parameters
headersThe headers to include
timeout_msThe 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
urlThe URL to GET
headersThe headers to include
timeout_msThe timeout in milliseconds
Returns
Response The HTTP response

◆ operator=()

HTTPClient & agents::HTTPClient::operator= ( HTTPClient && )
default

Move assignment operator for HTTPClient object.

Parameters
otherThe other HTTPClient to move from

◆ 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
urlThe URL to POST to
headersThe headers to include
bodyThe body to include
timeout_msThe timeout in milliseconds
write_cbOptional streaming write callback
multipartOptional 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
urlThe URL to POST to
headersThe headers to include
bodyThe body to include
timeout_msThe timeout in milliseconds
write_cbOptional streaming write callback
multipartOptional multipart form data
Returns
Response The HTTP response