RADLib
RADical C++ application framework
RADNet::RADHttpClient Class Reference

Small libcurl-backed HTTP client with sync and event-loop async APIs. More...

#include <RADNet.h>

+ Inheritance diagram for RADNet::RADHttpClient:
+ Collaboration diagram for RADNet::RADHttpClient:

Public Member Functions

 RADHttpClient (RADCore::EventLoop &loop)
 Creates an async client that posts results to loop. More...
 
void requestAsync (const RADHttpRequest &request)
 Starts an async request and emits finished/errorOccurred. More...
 
void getAsync (const RADCore::RADUrl &url)
 Starts an async GET request for url and emits finished/errorOccurred. More...
 
void getAsync (const std::string &url)
 Parses url and starts an async GET request. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Static Public Member Functions

static std::optional< RADHttpResponserequest (const RADHttpRequest &request, std::string *error=nullptr)
 Performs a blocking HTTP request. More...
 
static std::optional< RADHttpResponseget (const RADCore::RADUrl &url, std::string *error=nullptr)
 Performs a blocking GET request for url. More...
 
static std::optional< RADHttpResponseget (const std::string &url, std::string *error=nullptr)
 Parses url and performs a blocking GET request. More...
 
static std::optional< RADHttpResponsepost (const std::string &url, const std::string &body, const std::map< std::string, std::string > &headers={}, std::string *error=nullptr)
 Performs a blocking POST request. More...
 
static RADDnsResult resolve (const std::string &host)
 Resolves host to address strings. More...
 

Public Attributes

RADCore::Event< void(RADNet::RADHttpResponse) > finished
 Raised by async requests when a response completes. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised by async requests when request setup or transfer fails. More...
 

Detailed Description

Small libcurl-backed HTTP client with sync and event-loop async APIs.

Constructor & Destructor Documentation

◆ RADHttpClient()

RADNet::RADHttpClient::RADHttpClient ( RADCore::EventLoop loop)
explicit

Creates an async client that posts results to loop.

Member Function Documentation

◆ get() [1/2]

static std::optional<RADHttpResponse> RADNet::RADHttpClient::get ( const RADCore::RADUrl url,
std::string *  error = nullptr 
)
static

Performs a blocking GET request for url.

◆ get() [2/2]

static std::optional<RADHttpResponse> RADNet::RADHttpClient::get ( const std::string &  url,
std::string *  error = nullptr 
)
static

Parses url and performs a blocking GET request.

◆ getAsync() [1/2]

void RADNet::RADHttpClient::getAsync ( const RADCore::RADUrl url)

Starts an async GET request for url and emits finished/errorOccurred.

◆ getAsync() [2/2]

void RADNet::RADHttpClient::getAsync ( const std::string &  url)

Parses url and starts an async GET request.

◆ post()

static std::optional<RADHttpResponse> RADNet::RADHttpClient::post ( const std::string &  url,
const std::string &  body,
const std::map< std::string, std::string > &  headers = {},
std::string *  error = nullptr 
)
static

Performs a blocking POST request.

◆ request()

static std::optional<RADHttpResponse> RADNet::RADHttpClient::request ( const RADHttpRequest request,
std::string *  error = nullptr 
)
static

Performs a blocking HTTP request.

◆ requestAsync()

void RADNet::RADHttpClient::requestAsync ( const RADHttpRequest request)

Starts an async request and emits finished/errorOccurred.

◆ resolve()

static RADDnsResult RADNet::RADHttpClient::resolve ( const std::string &  host)
static

Resolves host to address strings.

Member Data Documentation

◆ errorOccurred

RADCore::Event<void (std::string) > RADNet::RADHttpClient::errorOccurred

Raised by async requests when request setup or transfer fails.

◆ finished

RADCore::Event<void (RADNet::RADHttpResponse) > RADNet::RADHttpClient::finished

Raised by async requests when a response completes.


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