olp-cpp-sdk  1.21.0
Public Types | Public Member Functions | List of all members
olp::client::OlpClient Class Reference

Executes HTTP requests by using the base url and the provided parameters and body. This class will handle retries based on the RetrySettings and will merge all similar URL requests into one. More...

#include <OlpClient.h>

Public Types

using ParametersType = std::multimap< std::string, std::string >
 An alias for the parameters and headers type.
 
using RequestBodyType = std::shared_ptr< std::vector< std::uint8_t > >
 An alias for the HTTP request body.
 

Public Member Functions

 OlpClient (const OlpClientSettings &settings, std::string base_url)
 Creates the OlpClient instance. More...
 
 OlpClient (const OlpClient &)
 A copy constructor.
 
OlpClientoperator= (const OlpClient &)
 An assignement operator.
 
 OlpClient (OlpClient &&) noexcept
 A move constructor.
 
OlpClientoperator= (OlpClient &&) noexcept
 A move assignement operator.
 
void SetBaseUrl (const std::string &base_url)
 Sets the base URL used for all requests. More...
 
std::string GetBaseUrl () const
 Gets the base URL. More...
 
ParametersTypeGetMutableDefaultHeaders ()
 Gets the default headers that are added to each request. More...
 
const OlpClientSettingsGetSettings () const
 Getter function to retrieve client settings. More...
 
CancellationToken CallApi (const std::string &path, const std::string &method, const ParametersType &query_params, const ParametersType &header_params, const ParametersType &form_params, const RequestBodyType &post_body, const std::string &content_type, const NetworkAsyncCallback &callback) const
 Executes the HTTP request through the network stack. More...
 
HttpResponse CallApi (std::string path, std::string method, ParametersType query_params, ParametersType header_params, ParametersType form_params, RequestBodyType post_body, std::string content_type, CancellationContext context) const
 Executes the HTTP request through the network stack in a blocking way. More...
 
HttpResponse CallApiStream (std::string path, std::string method, ParametersType query_params, ParametersType header_params, http::Network::DataCallback data_callback, RequestBodyType post_body, std::string content_type, CancellationContext context) const
 Executes the HTTP request through the network stack in a blocking way. The response content is consumed via data callback. More...
 

Detailed Description

Executes HTTP requests by using the base url and the provided parameters and body. This class will handle retries based on the RetrySettings and will merge all similar URL requests into one.

Constructor & Destructor Documentation

◆ OlpClient()

olp::client::OlpClient::OlpClient ( const OlpClientSettings settings,
std::string  base_url 
)

Creates the OlpClient instance.

Parameters
settingsThe OlpClientSettings instance.
base_urlThe base URL to be used for all outgoing requests.

Member Function Documentation

◆ CallApi() [1/2]

CancellationToken olp::client::OlpClient::CallApi ( const std::string &  path,
const std::string &  method,
const ParametersType query_params,
const ParametersType header_params,
const ParametersType form_params,
const RequestBodyType post_body,
const std::string &  content_type,
const NetworkAsyncCallback callback 
) const

Executes the HTTP request through the network stack.

Parameters
pathThe path that is appended to the base URL.
methodSelect one of the following methods: GET, POST, DELETE, or PUT.
query_paramsThe parameters that are appended to the URL path.
header_paramsThe headers used to customize the request.
form_paramsFor the POST request, populate form_params or post_body, but not both.
post_bodyFor the POST request, populate form_params or post_body, but not both. This data must not be modified until the request is completed.
content_typeThe content type for the post_body or form_params.
callbackThe function callback used to receive the HttpResponse instance.
Returns
The method used to call or to cancel the request.

◆ CallApi() [2/2]

HttpResponse olp::client::OlpClient::CallApi ( std::string  path,
std::string  method,
ParametersType  query_params,
ParametersType  header_params,
ParametersType  form_params,
RequestBodyType  post_body,
std::string  content_type,
CancellationContext  context 
) const

Executes the HTTP request through the network stack in a blocking way.

Parameters
pathThe path that is appended to the base URL.
methodSelect one of the following methods: GET, POST, DELETE, or PUT.
query_paramsThe parameters that are appended to the URL path.
header_paramsThe headers used to customize the request.
form_paramsFor the POST request, populate form_params or post_body, but not both.
post_bodyFor the POST request, populate form_params or post_body, but not both. This data must not be modified until the request is completed.
content_typeThe content type for the post_body or form_params.
contextThe CancellationContext instance that is used to cancel the request.
Returns
The HttpResponse instance.

◆ CallApiStream()

HttpResponse olp::client::OlpClient::CallApiStream ( std::string  path,
std::string  method,
ParametersType  query_params,
ParametersType  header_params,
http::Network::DataCallback  data_callback,
RequestBodyType  post_body,
std::string  content_type,
CancellationContext  context 
) const

Executes the HTTP request through the network stack in a blocking way. The response content is consumed via data callback.

Parameters
pathThe path that is appended to the base URL.
methodSelect one of the following methods: GET, POST, DELETE, or PUT.
query_paramsThe parameters that are appended to the URL path.
header_paramsThe headers used to customize the request.
data_callbackThe network data callback to retrieve content.
post_bodyFor the POST request, populate form_params or post_body, but not both. This data must not be modified until the request is completed.
content_typeThe content type for the post_body or form_params.
contextThe CancellationContext instance that is used to cancel the request.
Returns
The HttpResponse instance.

◆ GetBaseUrl()

std::string olp::client::OlpClient::GetBaseUrl ( ) const

Gets the base URL.

Returns
The base URL.

◆ GetMutableDefaultHeaders()

ParametersType& olp::client::OlpClient::GetMutableDefaultHeaders ( )

Gets the default headers that are added to each request.

Note
Do not change this while requests are ongoing.
Returns
The default headers.

◆ GetSettings()

const OlpClientSettings& olp::client::OlpClient::GetSettings ( ) const

Getter function to retrieve client settings.

Returns
The client settings

◆ SetBaseUrl()

void olp::client::OlpClient::SetBaseUrl ( const std::string &  base_url)

Sets the base URL used for all requests.

Note
The base URL can change over time and it is thread safe to change it.
Parameters
base_urlThe new base URL to be used for all outgoing requests.

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