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

A class for storing and managing HTTP request information. More...

#include <request.h>

Inherits RestLink::RequestInterface.

Inherited by RestLink::ServerRequest.

Public Types

enum  Attribute { CacheLoadControlAttribute , CacheSaveControlAttribute , CompressionAllowedAttribute }
 Defines configurable attributes that influence request behavior. More...
 
enum  UrlType { PublicUrl , SecretUrl }
 Defines the type of URL associated with the request. More...
 

Public Member Functions

 Request ()
 Default constructor for Request.
 
 Request (const char *endpoint)
 Constructs an Request object with a specified endpoint.
 
 Request (const QString &endpoint)
 Constructs an Request object with a specified endpoint.
 
 Request (const QUrl &url)
 Construct a Request object with a specified URL.
 
 Request (const RequestProcessing &processing)
 
 Request (const Request &other)
 Copy constructor for Request.
 
 Request (Request &&other)
 Move constructor for Request.
 
virtual ~Request ()
 Destructor for Request.
 
Requestoperator= (const Request &other)
 Copy assignment operator for Request.
 
Requestoperator= (const Request &&other)
 Move assignment operator for Request.
 
QString endpoint () const
 Retrieves the API endpoint associated with this request.
 
void setEndpoint (const QString &endpoint)
 Set the API endpoint associated with this request.
 
QUrl baseUrl () const
 Retrieves the API base url associated with this request.
 
void setBaseUrl (const QUrl &url)
 Set the API base url associated with this request.
 
QUrl url (UrlType type=SecretUrl) const
 Construct the full URL for the request.
 
QString urlPath () const
 Constructs the URL path for the request based on its parameters and endpoint.
 
QHttpHeaders httpHeaders () const
 Return the corresponding http headers for the request.
 
QVariant attribute (Attribute attribute) const
 Returns the attribute associated with the code code.
 
QVariant attribute (Attribute attribute, const QVariant &defaultValue) const
 Returns the attribute associated with the code code. Return defaultValue if the attribute has not been set.
 
void setAttribute (Attribute attribute, const QVariant &value)
 Set attribute value to the provided one.
 
RequestProcessing processing () const
 
void setProcessing (RequestProcessing processing)
 
AbstractControllercontroller () const
 Get the controller associated with the request.
 
void setController (AbstractController *controller)
 Associate a controller to the request.
 
Apiapi () const
 return the Api associated to this request
 
void setApi (Api *api)
 Associate an Api to this request.
 
QJsonObject toJsonObject () const
 
void swap (Request &other)
 Swaps the contents of this Request with another.
 

Static Public Member Functions

static Request fromJsonbject (const QJsonObject &object)
 
static Request merge (const Request &r1, const Request &r2)
 Merges two Request objects into a single request.
 

Protected Member Functions

 Request (RequestPrivate *d)
 

Protected Attributes

QSharedDataPointer< RequestPrivate > d_ptr
 

Detailed Description

A class for storing and managing HTTP request information.

The Request class encapsulates the essential details of an HTTP request, such as the endpoint, HTTP method, headers, query parameters, and more. It provides a convenient way to define and organize API requests before execution using RestLink.

Member Enumeration Documentation

◆ Attribute

Defines configurable attributes that influence request behavior.

These attributes control how the request interacts with caching and compression mechanisms.

Enumerator
CacheLoadControlAttribute 

Controls whether loading from cache is allowed when executing the request.

CacheSaveControlAttribute 

Controls whether the response of the request should be stored in cache.

CompressionAllowedAttribute 

Indicates whether the request supports receiving compressed responses.

◆ UrlType

Defines the type of URL associated with the request.

These types help differentiate between publicly accessible URLs and those containing sensitive data.

Enumerator
PublicUrl 

A URL intended for general or non-sensitive access.

SecretUrl 

A URL that may contain confidential or authentication-related information.

Constructor & Destructor Documentation

◆ Request() [1/8]

RestLink::Request::Request ( )

Default constructor for Request.

Initializes an empty Request object. This constructor sets up the object with default values for its members, ensuring a consistent state.

◆ Request() [2/8]

RestLink::Request::Request ( const char *  endpoint)

Constructs an Request object with a specified endpoint.

This constructor initializes the Request object with the given API endpoint. The endpoint will be used for making requests. Other parameters (such as headers or query parameters) will be empty by default.

Parameters
endpointThe API endpoint as a C-style string (const char*).
Note
endpoint must not include full path, only the url path relative to the base url provided on Api object.

◆ Request() [3/8]

RestLink::Request::Request ( const QString &  endpoint)

Constructs an Request object with a specified endpoint.

This constructor initializes the Request object with the given API endpoint. The endpoint will be used for making requests. Other parameters (such as headers or query parameters) will be empty by default.

Parameters
endpointThe API endpoint as a QString.
Note
endpoint must not include full path, only the url path relative to the base url provided on Api object.

◆ Request() [4/8]

RestLink::Request::Request ( const QUrl &  url)

Construct a Request object with a specified URL.

This constructor initialize the Request object with the given URL. The url must be include the scheme i.e starting with http/https.

Parameters
urlThe url as a QUrl.
Note
The provided url will be used as the base url, you can then launch the request directly on a RequestHandler without an Api object.

◆ Request() [5/8]

RestLink::Request::Request ( const RequestProcessing processing)

◆ Request() [6/8]

RestLink::Request::Request ( const Request other)

Copy constructor for Request.

Creates a new Request object as a copy of another. All data, including headers, URL, and parameters, are duplicated into the new instance.

Parameters
otherThe Request object to copy.

◆ Request() [7/8]

RestLink::Request::Request ( Request &&  other)

Move constructor for Request.

Transfers ownership of the data from another Request object to this one. The source object is left in a valid but unspecified state.

Parameters
otherThe Request object to move from.

◆ ~Request()

RestLink::Request::~Request ( )
virtual

Destructor for Request.

Cleans up any resources used by the Request object. Ensures all dynamically allocated memory is released.

◆ Request() [8/8]

RestLink::Request::Request ( RequestPrivate *  d)
protected

Member Function Documentation

◆ operator=() [1/2]

Request & RestLink::Request::operator= ( const Request other)

Copy assignment operator for Request.

Copies the content of another Request object to this one, replacing the existing data. Properly handles self-assignment.

Parameters
otherThe Request object to copy.
Returns
A reference to the updated Request object.

◆ operator=() [2/2]

Request & RestLink::Request::operator= ( const Request &&  other)

Move assignment operator for Request.

Transfers ownership of the data from another Request object to this one. The existing data in this object is replaced, and the source object is left in a valid but unspecified state.

Parameters
otherThe Request object to move from.
Returns
A reference to the updated Request object.

◆ endpoint()

QString RestLink::Request::endpoint ( ) const

Retrieves the API endpoint associated with this request.

Returns
The endpoint as a QString.

◆ setEndpoint()

void RestLink::Request::setEndpoint ( const QString &  endpoint)

Set the API endpoint associated with this request.

Parameters
endpointThe endpoint as a QString.

◆ baseUrl()

QUrl RestLink::Request::baseUrl ( ) const

Retrieves the API base url associated with this request.

Returns
The base url as a QUrl.
Note
If not base url has been explicitly set or is invalid, this method return the base url of the associated Api if it has been set.

◆ setBaseUrl()

void RestLink::Request::setBaseUrl ( const QUrl &  url)

Set the API base url associated with this request.

Parameters
urlThe new base url

◆ url()

QUrl RestLink::Request::url ( UrlType  type = SecretUrl) const

Construct the full URL for the request.

Parameters
typeThe url type to return.
Returns
The URL as a QUrl.

◆ urlPath()

QString RestLink::Request::urlPath ( ) const

Constructs the URL path for the request based on its parameters and endpoint.

Returns
The constructed URL path as a QString.
Deprecated:

◆ httpHeaders()

QHttpHeaders RestLink::Request::httpHeaders ( ) const

Return the corresponding http headers for the request.

Returns
The corresponding http headers for the request.

◆ attribute() [1/2]

QVariant RestLink::Request::attribute ( Attribute  attribute) const

Returns the attribute associated with the code code.

Parameters
attributeThe attribute for which we want value.
Returns
The attribute value as a QVariant

◆ attribute() [2/2]

QVariant RestLink::Request::attribute ( Attribute  attribute,
const QVariant &  defaultValue 
) const

Returns the attribute associated with the code code. Return defaultValue if the attribute has not been set.

Parameters
attributeThe attribute for which we want value.
Returns
The attribute value as a QVariant

◆ setAttribute()

void RestLink::Request::setAttribute ( Attribute  attribute,
const QVariant &  value 
)

Set attribute value to the provided one.

Parameters
attributeThe attribute for which value must ve set.
valueThe value of the attribute to set.

◆ processing()

RequestProcessing RestLink::Request::processing ( ) const

◆ setProcessing()

void RestLink::Request::setProcessing ( RequestProcessing  processing)

◆ controller()

AbstractController * RestLink::Request::controller ( ) const

Get the controller associated with the request.

◆ setController()

void RestLink::Request::setController ( AbstractController controller)

Associate a controller to the request.

Parameters
controllerThe controller to set.
Note
The controller will be used to process the request in meantime except if it's used with a special RestLink endpoint such as /restlink/register-controller.

◆ api()

Api * RestLink::Request::api ( ) const

return the Api associated to this request

Returns
The Api.

◆ setApi()

void RestLink::Request::setApi ( Api api)

Associate an Api to this request.

Parameters
apiThe Api to associate

◆ toJsonObject()

QJsonObject RestLink::Request::toJsonObject ( ) const

◆ fromJsonbject()

Request RestLink::Request::fromJsonbject ( const QJsonObject &  object)
static

◆ swap()

void RestLink::Request::swap ( Request other)

Swaps the contents of this Request with another.

Parameters
otherThe Request instance to swap with.

◆ merge()

Request RestLink::Request::merge ( const Request r1,
const Request r2 
)
static

Merges two Request objects into a single request.

Parameters
r1The first Request to merge.
r2The second Request to merge.
Returns
A new Request containing merged properties and parameters.

Member Data Documentation

◆ d_ptr

QSharedDataPointer<RequestPrivate> RestLink::Request::d_ptr
protected