C++ REST client module#

namespace client#

Namespace including the API Eigen Example Client implemented in C++.

Functions

void print_response(const RestClient::Response &response)#

Method for printing out Response objects in a common format.

Parameters:

response – the RestClient::Response object.

class EigenClient#

Class containing the basic functionalities to interact with the API Eigen Example server.

Public Functions

EigenClient(const std::string &baseUrl, const std::string &user = std::string{}, const std::string &pwd = std::string{}, const int timeout = 10, const bool debug_log = false)#

Construct a new Eigen Client object.

Parameters:
  • baseUrl – the API Eigen Example server endpoint (e.g. http://127.0.0.1:18080).

  • user – (optional) the user in case of BasicAuthentication mechanism required. Default: empty.

  • pwd – (optional) the password in case of BasicAuthentication mechanism required. Default: empty.

  • timeout – (optional) the timeout to be set for aborting connection. Default: 10.

  • debug_log – whether to show the enhanced debugging logs or not. Default: false.

~EigenClient()#

Destroy the Eigen Client object.

void request_greeting()#

Method to request a greeting from the endpoint server.

std::vector<double> add_vectors(const std::vector<double> &vec1, const std::vector<double> &vec2)#

Method in charge of requesting a vector addition to the endpoint server.

Parameters:
  • vec1 – the first vector involved in the operation.

  • vec2 – the second vector involved in the operation.

Returns:

std::vector<double>

double multiply_vectors(const std::vector<double> &vec1, const std::vector<double> &vec2)#

Method in charge of requesting a vector dot product to the endpoint server.

Parameters:
  • vec1 – the first vector involved in the operation.

  • vec2 – the second vector involved in the operation.

Returns:

double

std::vector<std::vector<double>> add_matrices(const std::vector<std::vector<double>> &mat1, const std::vector<std::vector<double>> &mat2)#

Method in charge of requesting a matrix addition to the endpoint server.

Parameters:
  • mat1 – the first matrix involved in the operation.

  • mat2 – the second matrix involved in the operation.

Returns:

std::vector<std::vector<double>>

std::vector<std::vector<double>> multiply_matrices(const std::vector<std::vector<double>> &mat1, const std::vector<std::vector<double>> &mat2)#

Method in charge of requesting a matrix multiplication to the endpoint server.

Parameters:
  • mat1 – the first matrix involved in the operation.

  • mat2 – the second matrix involved in the operation.

Returns:

std::vector<std::vector<double>>

Private Functions

int post_vector(const std::vector<double> &input)#

Method in charge of connecting to the endpoint server to POST a Vector Resource.

Parameters:

input – the vector we are interested in posting.

Returns:

int - the ID of the posted vector.

int post_matrix(const std::vector<std::vector<double>> &input)#

Method in charge of connecting to the endpoint server to POST a Matrix Resource.

Parameters:

input – the matrix we are interested in posting.

Returns:

int - the ID of the posted matrix.

Json::Value vector_to_json(const std::vector<double> &input)#

Method in charge of transforming a std::vector of type double to a JSON object.

Parameters:

input – the vector to be formatted as a JSON object.

Returns:

Json::Value

Json::Value matrix_to_json(const std::vector<std::vector<double>> &input)#

Method in charge of transforming a std::vector<std::vecto> of type double to a JSON object.

Parameters:

input – the matrix to be formatted as a JSON object.

Returns:

Json::Value

std::vector<double> json_to_vector(const Json::Value &input)#

Method in charge of transforming a JSON object which represents a vector into a std::vector<double>.

Parameters:

input – the JSON object to be formatted as a vector.

Returns:

std::vector<double>

std::vector<std::vector<double>> json_to_matrix(const Json::Value &input)#

Method in charge of transforming a JSON object which represents a matrix into a std::vector<std::vector<double>>.

Parameters:

input – the JSON object to be formatted as a matrix.

Returns:

std::vector<std::vector<double>>

Private Members

RestClient::Connection *_conn = {nullptr}#

The connection pointer to the endpoint server.

bool _debug_log#

Boolean indicating whether to show the debugging logs or not.