AuxPort 0.2
Modules for Audio Software Development
Loading...
Searching...
No Matches
AuxPort::Extensions::AuxCurl Class Reference

This class provides a C++ wrapper for the curl library. More...

#include <AuxCurl.h>

Public Types

enum  RequestType { GET , POST }
 Specifies the Type of Request to perform. More...
 

Public Member Functions

 AuxCurl ()
 Initializes the AuxCurl Object.
 
 ~AuxCurl ()
 Destructs and cleans up the AuxCurl Object.
 
void setURL (const std::string &URL)
 Sets the target URL for the Request.
 
void addHeaders (const std::vector< AuxPort::StringPair > &headers)
 Specify the Headers to be passed in the Request.
 
void clearHeaders ()
 Clears all custom provided headers and sets the CURL default Headers.
 
void setPostFields (const std::string &postFields)
 Sets the HTTP POST Fields. The POST fields are sent exactly as provided to the function. Also, make sure to set the 'content-type' header corresponding to your postFields.
 
void setResponseHandler (const std::function< void(const std::string &responseData)> &responseHandler)
 Sets a custom handler to handle the Response Data.
 
bool sendRequest (const RequestType &type)
 Sends the request to the target URL and executes the response Handler upon completion.
 
std::string getResponseAsString ()
 Returns the Response Data of the last sent Request as a String Object.
 

Detailed Description

This class provides a C++ wrapper for the curl library.

Definition at line 54 of file AuxCurl.h.

Member Enumeration Documentation

◆ RequestType

Specifies the Type of Request to perform.

Definition at line 60 of file AuxCurl.h.

Constructor & Destructor Documentation

◆ AuxCurl()

AuxPort::Extensions::AuxCurl::AuxCurl ( )

Initializes the AuxCurl Object.

Definition at line 3 of file AuxCurl.cpp.

◆ ~AuxCurl()

AuxPort::Extensions::AuxCurl::~AuxCurl ( )

Destructs and cleans up the AuxCurl Object.

Definition at line 13 of file AuxCurl.cpp.

Member Function Documentation

◆ addHeaders()

void AuxPort::Extensions::AuxCurl::addHeaders ( const std::vector< AuxPort::StringPair > & headers)

Specify the Headers to be passed in the Request.

Note
A Header added once will be used for all subsequent requests until it is cleared/overwritten.
To clear/unset a single header, provide the header name with an empty value.
To clear all headers at once, consider the clearHeaders() function.
When called again, this function simply appends the provided Headers to already specified ones.

Definition at line 24 of file AuxCurl.cpp.

◆ clearHeaders()

void AuxPort::Extensions::AuxCurl::clearHeaders ( )

Clears all custom provided headers and sets the CURL default Headers.

Definition at line 33 of file AuxCurl.cpp.

◆ getResponseAsString()

std::string AuxPort::Extensions::AuxCurl::getResponseAsString ( )

Returns the Response Data of the last sent Request as a String Object.

Definition at line 77 of file AuxCurl.cpp.

◆ sendRequest()

bool AuxPort::Extensions::AuxCurl::sendRequest ( const RequestType & type)

Sends the request to the target URL and executes the response Handler upon completion.

Returns
Returns true if there was no error in the transfer, otherwise false.

Definition at line 51 of file AuxCurl.cpp.

◆ setPostFields()

void AuxPort::Extensions::AuxCurl::setPostFields ( const std::string & postFields)

Sets the HTTP POST Fields. The POST fields are sent exactly as provided to the function. Also, make sure to set the 'content-type' header corresponding to your postFields.

Definition at line 40 of file AuxCurl.cpp.

◆ setResponseHandler()

void AuxPort::Extensions::AuxCurl::setResponseHandler ( const std::function< void(const std::string &responseData)> & responseHandler)

Sets a custom handler to handle the Response Data.

The passed function/lambda will be called after completion of an request and will receive the Response Data as a string argument. You can provide access to local variables using lambda captures. Example Usage:

...
std::string res;
obj.setResponseHandler( [&res] (const std::string& responseData) {
res = responseData;
} );
This class provides a C++ wrapper for the curl library.
Definition AuxCurl.h:55
void setResponseHandler(const std::function< void(const std::string &responseData)> &responseHandler)
Sets a custom handler to handle the Response Data.
Definition AuxCurl.cpp:46

Definition at line 46 of file AuxCurl.cpp.

◆ setURL()

void AuxPort::Extensions::AuxCurl::setURL ( const std::string & URL)

Sets the target URL for the Request.

Definition at line 19 of file AuxCurl.cpp.


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