RestLink 2.2.0
Powerfull Rest Client for Qt
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RestLink::ApiBase Class Referenceabstract

The ApiBase class provides methods for making HTTP requests (HEAD, GET, POST, PUT, PATCH, DELETE) and handling responses. More...

#include <apibase.h>

Inherits QObject, and RestLink::RequestInterface.

Inherited by RestLink::Api.

Public Member Functions

virtual ~ApiBase ()
 Destructor for ApiBase.
 
virtual QUrl url () const =0
 
virtual QLocale locale () const
 Returns the api locale.
 
void head (const Request &request, const ApiRunCallback &callback)
 Makes a HEAD request and calls the provided callback upon completion.
 
Responsehead (const Request &request)
 Makes a HEAD request and returns the Response object.
 
void get (const Request &request, const ApiRunCallback &callback)
 Makes a GET request and calls the provided callback upon completion.
 
Responseget (const Request &request)
 Makes a GET request and returns the Response object.
 
void post (const Request &request, const Body &body, const ApiRunCallback &callback)
 Makes a POST request with a body and calls the provided callback upon completion.
 
Responsepost (const Request &request, const Body &body)
 Makes a POST request with a body and returns the Response object.
 
void put (const Request &request, const Body &body, const ApiRunCallback &callback)
 Makes a PUT request with a body and calls the provided callback upon completion.
 
Responseput (const Request &request, const Body &body)
 Makes a PUT request with a body and returns the Response object.
 
void patch (const Request &request, const Body &body, const ApiRunCallback &callback)
 Makes a PATCH request with a body and calls the provided callback upon completion.
 
Responsepatch (const Request &request, const Body &body)
 Makes a PATCH request with a body and returns the Response object.
 
void deleteResource (const Request &request, const ApiRunCallback &callback)
 Makes a DELETE request and calls the provided callback upon completion.
 
ResponsedeleteResource (const Request &request)
 Makes a DELETE request and returns the Response object.
 
virtual Responsesend (AbstractRequestHandler::Method method, const Request &request, const Body &body)
 
virtual QString userAgent () const
 Returns the user agent string for the API.
 
NetworkManagernetworkManager () const
 Returns the network manager used by the ApiBase class.
 
void setNetworkManager (NetworkManager *manager)
 Sets the network manager for the ApiBase class.
 

Protected Member Functions

 ApiBase (ApiBasePrivate *d, QObject *parent)
 

Protected Attributes

QScopedPointer< ApiBasePrivated_ptr
 

Detailed Description

The ApiBase class provides methods for making HTTP requests (HEAD, GET, POST, PUT, PATCH, DELETE) and handling responses.

This class encapsulates the functionality for interacting with an API by providing methods for various HTTP methods. It manages request interceptors, constructs network requests, and handles the creation of network replies and responses. The class supports asynchronous communication, allowing the user to pass callbacks for handling responses.

Note
This class must not be used directly, use Api class instead.
See also
Request, Response, RequestInterceptor

Constructor & Destructor Documentation

◆ ~ApiBase()

RestLink::ApiBase::~ApiBase ( )
virtual

Destructor for ApiBase.

◆ ApiBase()

RestLink::ApiBase::ApiBase ( ApiBasePrivate d,
QObject *  parent 
)
protected

Member Function Documentation

◆ url()

virtual QUrl RestLink::ApiBase::url ( ) const
pure virtual

Implemented in RestLink::Api.

◆ locale()

QLocale RestLink::ApiBase::locale ( ) const
virtual

Returns the api locale.

Returns
QLocale representing the api locale.
Note
This locale is used to set ACCEPT-LANGUAGE header only, if you want to pass it to the API you are using, you must do it manually according to the used API documentation.

Reimplemented in RestLink::Api.

◆ head() [1/2]

void RestLink::ApiBase::head ( const Request request,
const ApiRunCallback callback 
)

Makes a HEAD request and calls the provided callback upon completion.

Parameters
requestThe Request object to be sent.
callbackThe callback function to be invoked once the request completes.

◆ head() [2/2]

Response * RestLink::ApiBase::head ( const Request request)

Makes a HEAD request and returns the Response object.

Parameters
requestThe Request object to be sent.
Returns
A Response object containing the result of the HEAD request.

◆ get() [1/2]

void RestLink::ApiBase::get ( const Request request,
const ApiRunCallback callback 
)

Makes a GET request and calls the provided callback upon completion.

Parameters
requestThe Request object to be sent.
callbackThe callback function to be invoked once the request completes.

◆ get() [2/2]

Response * RestLink::ApiBase::get ( const Request request)

Makes a GET request and returns the Response object.

Parameters
requestThe Request object to be sent.
Returns
A Response object containing the result of the GET request.

◆ post() [1/2]

void RestLink::ApiBase::post ( const Request request,
const Body body,
const ApiRunCallback callback 
)

Makes a POST request with a body and calls the provided callback upon completion.

Parameters
requestThe Request object to be sent.
bodyThe Body object containing the data to be sent in the request.
callbackThe callback function to be invoked once the request completes.

◆ post() [2/2]

Response * RestLink::ApiBase::post ( const Request request,
const Body body 
)

Makes a POST request with a body and returns the Response object.

Parameters
requestThe Request object to be sent.
bodyThe Body object containing the data to be sent in the request.
Returns
A Response object containing the result of the POST request.

◆ put() [1/2]

void RestLink::ApiBase::put ( const Request request,
const Body body,
const ApiRunCallback callback 
)

Makes a PUT request with a body and calls the provided callback upon completion.

Parameters
requestThe Request object to be sent.
bodyThe Body object containing the data to be sent in the request.
callbackThe callback function to be invoked once the request completes.

◆ put() [2/2]

Response * RestLink::ApiBase::put ( const Request request,
const Body body 
)

Makes a PUT request with a body and returns the Response object.

Parameters
requestThe Request object to be sent.
bodyThe Body object containing the data to be sent in the request.
Returns
A Response object containing the result of the PUT request.

◆ patch() [1/2]

void RestLink::ApiBase::patch ( const Request request,
const Body body,
const ApiRunCallback callback 
)

Makes a PATCH request with a body and calls the provided callback upon completion.

Parameters
requestThe Request object to be sent.
bodyThe Body object containing the data to be sent in the request.
callbackThe callback function to be invoked once the request completes.

◆ patch() [2/2]

Response * RestLink::ApiBase::patch ( const Request request,
const Body body 
)

Makes a PATCH request with a body and returns the Response object.

Parameters
requestThe Request object to be sent.
bodyThe Body object containing the data to be sent in the request.
Returns
A Response object containing the result of the PATCH request.

◆ deleteResource() [1/2]

void RestLink::ApiBase::deleteResource ( const Request request,
const ApiRunCallback callback 
)

Makes a DELETE request and calls the provided callback upon completion.

Parameters
requestThe Request object to be sent.
callbackThe callback function to be invoked once the request completes.

◆ deleteResource() [2/2]

Response * RestLink::ApiBase::deleteResource ( const Request request)

Makes a DELETE request and returns the Response object.

Parameters
requestThe Request object to be sent.
Returns
A Response object containing the result of the DELETE request.

◆ send()

Response * RestLink::ApiBase::send ( AbstractRequestHandler::Method  method,
const Request request,
const Body body 
)
virtual

Reimplemented in RestLink::Api.

◆ userAgent()

QString RestLink::ApiBase::userAgent ( ) const
virtual

Returns the user agent string for the API.

Returns
A string representing the user agent.

Reimplemented in RestLink::Api.

◆ networkManager()

NetworkManager * RestLink::ApiBase::networkManager ( ) const

Returns the network manager used by the ApiBase class.

This function retrieves the current instance of the QNetworkAccessManager that is used for making network requests.

Returns
A pointer to the QNetworkAccessManager instance.

◆ setNetworkManager()

void RestLink::ApiBase::setNetworkManager ( NetworkManager manager)

Sets the network manager for the ApiBase class.

This function allows setting a custom QNetworkAccessManager instance to be used for network requests.

Parameters
managerA pointer to the QNetworkAccessManager instance to be set.

Member Data Documentation

◆ d_ptr

QScopedPointer<ApiBasePrivate> RestLink::ApiBase::d_ptr
protected