Agents 1.6.9
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  MultipartFormData
 Multipart form data part. More...
struct  Response
 Normalized response returned by the wrapper functions. More...

Public Types

using Headers = std::map<std::string, std::string>
 http headers
using Params = std::multimap<std::string, std::string>
 http params
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 &&) noexcept
 Safe move constructor.
HTTPClientoperator= (HTTPClient &&) noexcept
 Safe move constructor with equals operator.
Response Get (const std::string &url, const Headers &headers={}, int timeout_ms=30000)
 Instance GET (persistent).
Response Post (const std::string &url, const Headers &headers, const std::string &body, int timeout_ms=30000, WriteCallback write_cb=nullptr, const std::vector< MultipartFormData > &multipart={})
 Instance POST (persistent).

Static Public Member Functions

static Response post (const std::string &url, const Headers &headers, const std::string &body, int timeout_ms=30000, WriteCallback write_cb=nullptr, const std::vector< MultipartFormData > &multipart={})
 Static POST (transient).
static Response get (const std::string &url, const Headers &headers, int timeout_ms=30000)
 Static GET (transient).
static Response get (const std::string &url, const Params &params, const Headers &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()

agents::HTTPClient::HTTPClient ( const std::string & url)
explicit

Construct a persistent HTTPClient.

Establishes the base connection context. The TCP connection is maintained alive where possible (Keep-Alive).

Member Function Documentation

◆ Get()

Response agents::HTTPClient::Get ( const std::string & url,
const Headers & headers = {},
int timeout_ms = 30000 )

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 Headers & headers,
int timeout_ms = 30000 )
static

Static GET (transient).

Parameters
urlThe URL to GET.
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 Params & params,
const Headers & headers,
int timeout_ms = 30000 )
static

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.

◆ operator=()

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

Safe move constructor with equals operator.

Returns
HTTPClient& Http client object

◆ Post()

Response agents::HTTPClient::Post ( const std::string & url,
const Headers & headers,
const std::string & body,
int timeout_ms = 30000,
WriteCallback write_cb = nullptr,
const std::vector< MultipartFormData > & multipart = {} )

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 Headers & headers,
const std::string & body,
int timeout_ms = 30000,
WriteCallback write_cb = nullptr,
const std::vector< MultipartFormData > & multipart = {} )
static

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.