DuxReiNummariae 1.0.0-alpha.23
Simple and powerful budgeting application
 
Loading...
Searching...
No Matches
drn::networking::RequestBuilder Class Reference

A means to build a network request for sending. More...

#include <RequestBuilder.hpp>

Collaboration diagram for drn::networking::RequestBuilder:

Public Member Functions

 RequestBuilder (Scheme scheme, ::QString host, ::QStringList pathSegments={})
 Full initialisation constructor starting with its scheme and host. When a scheme has a default port, the port is set to it.
 
RequestBuilderaddHeader (const ::QString &key, const ::QString &value)
 Adds a header to the request.
 
RequestBuilderaddParameter (const ::QString &key, const ::QString &value)
 Adds a parameter to the URL.
 
RequestBuilderaddPathSegment (const ::QString &segment)
 Adds a path segment to the URL.
 
RequestBuilderaddQuery (const ::QString &key, const ::QString &value)
 Adds a query parameter to the URL.
 
QNetworkRequest build () const noexcept
 Builds and returns a QNetworkRequest object based on the current configuration.
 
const std::optional<::QString > & fragment () const noexcept
 The fragment portion of the URL, if it has been set.
 
const std::unordered_map<::QString, ::QString > & headers () const noexcept
 The headers that have been added in a key-value pair.
 
const ::QString & host () const noexcept
 The host name to connect to.
 
const std::unordered_map<::QString, ::QString > & parameters () const noexcept
 The parameters that have been added in a key-value pair.
 
const std::optional<::QString > & password () const noexcept
 The optional password for authentication if it has been set. If no password is set, the optional will be empty.
 
const ::QStringList & pathSegments () const noexcept
 
const std::optional< std::uint16_t > & port () const noexcept
 The optional port number for the network request.
 
const ::QUrlQuery & queries () const noexcept
 The queries that have been added in a key-value pair.
 
Scheme scheme () const noexcept
 The current URI scheme used in the network request.
 
RequestBuildersetCredentials (const ::QString &username, const std::optional<::QString > &password=std::nullopt)
 Sets the credentials for authentication.
 
RequestBuildersetFragment (const ::QString &fragment)
 Sets the fragment portion of the URL.
 
RequestBuildersetPort (const std::uint16_t port)
 Sets the port number.
 
const std::optional<::QString > & userName () const noexcept
 The user-name used for authentication if it is set. If the user-name is not set, the returned optional will be empty.
 

Detailed Description

A means to build a network request for sending.

Constructor & Destructor Documentation

◆ RequestBuilder()

drn::networking::RequestBuilder::RequestBuilder ( Scheme scheme,
::QString host,
::QStringList pathSegments = {} )

Full initialisation constructor starting with its scheme and host. When a scheme has a default port, the port is set to it.

Exceptions
HostErrorWhen the hostname is invalid.
Parameters
schemeThe URI scheme to use (e.g., HTTP, HTTPS, FTP).
hostThe hostname to connect to.
pathSegmentsThe list of path segments for the URL. Path segments represent the individual parts of the URL path.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ addHeader()

RequestBuilder & drn::networking::RequestBuilder::addHeader ( const ::QString & key,
const ::QString & value )

Adds a header to the request.

Parameters
keyThe header field name.
valueThe header field value.
Returns
Reference to the current RequestBuilder instance for method chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addParameter()

RequestBuilder & drn::networking::RequestBuilder::addParameter ( const ::QString & key,
const ::QString & value )

Adds a parameter to the URL.

Parameters
keyThe parameter key.
valueThe parameter value.
Returns
Reference to the current NetworkRequestBuilder for method chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addPathSegment()

RequestBuilder & drn::networking::RequestBuilder::addPathSegment ( const ::QString & segment)

Adds a path segment to the URL.

Parameters
segmentThe path segment to add.
Returns
Reference to the current NetworkRequestBuilder for method chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addQuery()

RequestBuilder & drn::networking::RequestBuilder::addQuery ( const ::QString & key,
const ::QString & value )

Adds a query parameter to the URL.

Parameters
keyThe query parameter key.
valueThe query parameter value.
Returns
Reference to the current NetworkRequestBuilder for method chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build()

QNetworkRequest drn::networking::RequestBuilder::build ( ) const
noexcept

Builds and returns a QNetworkRequest object based on the current configuration.

Returns
The constructed QNetworkRequest.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fragment()

const std::optional<::QString > & drn::networking::RequestBuilder::fragment ( ) const
nodiscardnoexcept

The fragment portion of the URL, if it has been set.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ headers()

const std::unordered_map<::QString, ::QString > & drn::networking::RequestBuilder::headers ( ) const
nodiscardnoexcept

The headers that have been added in a key-value pair.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ host()

const ::QString & drn::networking::RequestBuilder::host ( ) const
nodiscardnoexcept

The host name to connect to.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parameters()

const std::unordered_map<::QString, ::QString > & drn::networking::RequestBuilder::parameters ( ) const
nodiscardnoexcept

The parameters that have been added in a key-value pair.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ password()

const std::optional<::QString > & drn::networking::RequestBuilder::password ( ) const
nodiscardnoexcept

The optional password for authentication if it has been set. If no password is set, the optional will be empty.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pathSegments()

const ::QStringList & drn::networking::RequestBuilder::pathSegments ( ) const
nodiscardnoexcept

The list of path segments for the URL. Path segments represent the individual parts of the URL path.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ port()

const std::optional< std::uint16_t > & drn::networking::RequestBuilder::port ( ) const
nodiscardnoexcept

The optional port number for the network request.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queries()

const ::QUrlQuery & drn::networking::RequestBuilder::queries ( ) const
nodiscardnoexcept

The queries that have been added in a key-value pair.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheme()

Scheme drn::networking::RequestBuilder::scheme ( ) const
nodiscardnoexcept

The current URI scheme used in the network request.

Here is the caller graph for this function:

◆ setCredentials()

RequestBuilder & drn::networking::RequestBuilder::setCredentials ( const ::QString & username,
const std::optional<::QString > & password = std::nullopt )

Sets the credentials for authentication.

Parameters
usernameThe username for authentication.
passwordThe optional password for authentication.
Returns
Reference to the current NetworkRequestBuilder for method chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFragment()

RequestBuilder & drn::networking::RequestBuilder::setFragment ( const ::QString & fragment)

Sets the fragment portion of the URL.

Parameters
fragmentThe fragment to set.
Returns
Reference to the current NetworkRequestBuilder for method chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPort()

RequestBuilder & drn::networking::RequestBuilder::setPort ( const std::uint16_t port)

Sets the port number.

Parameters
portThe port number to use.
Returns
Reference to the current NetworkRequestBuilder for method chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ userName()

const std::optional<::QString > & drn::networking::RequestBuilder::userName ( ) const
nodiscardnoexcept

The user-name used for authentication if it is set. If the user-name is not set, the returned optional will be empty.

Here is the call graph for this function:
Here is the caller graph for this function: