RAVENNAKIT
Loading...
Searching...
No Matches
rav::HttpClientBase Class Referenceabstract

#include <http_client.hpp>

Inheritance diagram for rav::HttpClientBase:
rav::HttpClient

Public Types

using Request = http::request<http::string_body>
using Response = http::response<http::string_body>
using ResponseCallback = std::function<void(boost::system::result<http::response<http::string_body>> response)>
 Callback type for async requests.

Public Member Functions

virtual ~HttpClientBase ()=default
virtual void set_host (const boost::urls::url &url)=0
 Sets the host to connect to.
virtual void set_host (std::string_view url)=0
 Sets the host to connect to.
virtual void set_host (std::string_view host, std::string_view service)=0
 Sets the host to connect to.
virtual void get_async (std::string_view target, ResponseCallback callback)=0
 Asynchronous GET request.
virtual void post_async (std::string_view target, std::string body, ResponseCallback callback, std::string_view content_type)=0
 Asynchronous POST request to the target of the URL, or the root if no target is specified.
virtual void delete_async (std::string_view target, ResponseCallback callback)=0
 Asynchronous DELETE request to the target of the URL, or the root if no target is specified.
virtual void request_async (http::verb method, std::string_view target, std::string body, std::string_view content_type, ResponseCallback callback)=0
 Asynchronous request.
virtual void cancel_outstanding_requests ()=0
 Clears all scheduled requests if there are any.
virtual const std::string & get_host () const =0
virtual const std::string & get_service () const =0

Static Public Attributes

static constexpr auto k_default_port = "80"
 When no port is specified in the urls, the default port is used.

Detailed Description

Definition at line 40 of file http_client.hpp.

Member Typedef Documentation

◆ Request

using rav::HttpClientBase::Request = http::request<http::string_body>

Definition at line 47 of file http_client.hpp.

◆ Response

using rav::HttpClientBase::Response = http::response<http::string_body>

Definition at line 48 of file http_client.hpp.

◆ ResponseCallback

using rav::HttpClientBase::ResponseCallback = std::function<void(boost::system::result<http::response<http::string_body>> response)>

Callback type for async requests.

Definition at line 51 of file http_client.hpp.

Constructor & Destructor Documentation

◆ ~HttpClientBase()

virtual rav::HttpClientBase::~HttpClientBase ( )
virtualdefault

Member Function Documentation

◆ cancel_outstanding_requests()

virtual void rav::HttpClientBase::cancel_outstanding_requests ( )
pure virtual

Clears all scheduled requests if there are any.

Otherwise, this function has no effect.

Implemented in rav::HttpClient.

◆ delete_async()

virtual void rav::HttpClientBase::delete_async ( std::string_view target,
ResponseCallback callback )
pure virtual

Asynchronous DELETE request to the target of the URL, or the root if no target is specified.

Parameters
targetThe target to request.
callbackThe callback to call when the request is complete.

Implemented in rav::HttpClient.

◆ get_async()

virtual void rav::HttpClientBase::get_async ( std::string_view target,
ResponseCallback callback )
pure virtual

Asynchronous GET request.

The callback's lifetime will be tied to the io_context so make sure referenced objects are kept alive until the callback is called.

Parameters
targetThe target to request.
callbackThe callback to call when the request is complete.

Implemented in rav::HttpClient.

◆ get_host()

virtual const std::string & rav::HttpClientBase::get_host ( ) const
nodiscardpure virtual
Returns
The host that is currently set for this client.

Implemented in rav::HttpClient.

◆ get_service()

virtual const std::string & rav::HttpClientBase::get_service ( ) const
nodiscardpure virtual
Returns
The service (port) that this current client is set for this client.

Implemented in rav::HttpClient.

◆ post_async()

virtual void rav::HttpClientBase::post_async ( std::string_view target,
std::string body,
ResponseCallback callback,
std::string_view content_type )
pure virtual

Asynchronous POST request to the target of the URL, or the root if no target is specified.

Parameters
targetThe target to request.
bodyThe body to send with the request.
callbackThe callback to call when the request is complete.
content_typeThe content type of the body, e.g. "application/json". If not specified, defaults to "application/json".

Implemented in rav::HttpClient.

◆ request_async()

virtual void rav::HttpClientBase::request_async ( http::verb method,
std::string_view target,
std::string body,
std::string_view content_type,
ResponseCallback callback )
pure virtual

Asynchronous request.

Parameters
methodThe HTTP method to use for the request.
targetThe target to request.
bodyThe optional body to send with the request.
content_type
callbackThe callback to call when the request is complete.

Implemented in rav::HttpClient.

◆ set_host() [1/3]

virtual void rav::HttpClientBase::set_host ( const boost::urls::url & url)
pure virtual

Sets the host to connect to.

Parameters
urlThe url with the host info.

Implemented in rav::HttpClient.

◆ set_host() [2/3]

virtual void rav::HttpClientBase::set_host ( std::string_view host,
std::string_view service )
pure virtual

Sets the host to connect to.

Parameters
hostThe host to connect to.
serviceThe service (port) to connect to.

Implemented in rav::HttpClient.

◆ set_host() [3/3]

virtual void rav::HttpClientBase::set_host ( std::string_view url)
pure virtual

Sets the host to connect to.

Parameters
urlThe host to connect to.

Implemented in rav::HttpClient.

Member Data Documentation

◆ k_default_port

auto rav::HttpClientBase::k_default_port = "80"
staticconstexpr

When no port is specified in the urls, the default port is used.

Definition at line 45 of file http_client.hpp.


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