A means to build a network request for sending. More...
#include <RequestBuilder.hpp>
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. | |
RequestBuilder & | addHeader (const ::QString &key, const ::QString &value) |
Adds a header to the request. | |
RequestBuilder & | addParameter (const ::QString &key, const ::QString &value) |
Adds a parameter to the URL. | |
RequestBuilder & | addPathSegment (const ::QString &segment) |
Adds a path segment to the URL. | |
RequestBuilder & | addQuery (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. | |
RequestBuilder & | setCredentials (const ::QString &username, const std::optional<::QString > &password=std::nullopt) |
Sets the credentials for authentication. | |
RequestBuilder & | setFragment (const ::QString &fragment) |
Sets the fragment portion of the URL. | |
RequestBuilder & | setPort (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. | |
A means to build a network request for sending.
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.
HostError | When the hostname is invalid. |
scheme | The URI scheme to use (e.g., HTTP, HTTPS, FTP). |
host | The hostname to connect to. |
pathSegments | The list of path segments for the URL. Path segments represent the individual parts of the URL path. |
RequestBuilder & drn::networking::RequestBuilder::addHeader | ( | const ::QString & | key, |
const ::QString & | value ) |
Adds a header to the request.
key | The header field name. |
value | The header field value. |
RequestBuilder & drn::networking::RequestBuilder::addParameter | ( | const ::QString & | key, |
const ::QString & | value ) |
Adds a parameter to the URL.
key | The parameter key. |
value | The parameter value. |
RequestBuilder & drn::networking::RequestBuilder::addPathSegment | ( | const ::QString & | segment | ) |
Adds a path segment to the URL.
segment | The path segment to add. |
RequestBuilder & drn::networking::RequestBuilder::addQuery | ( | const ::QString & | key, |
const ::QString & | value ) |
Adds a query parameter to the URL.
key | The query parameter key. |
value | The query parameter value. |
|
noexcept |
Builds and returns a QNetworkRequest object based on the current configuration.
|
nodiscardnoexcept |
The fragment portion of the URL, if it has been set.
|
nodiscardnoexcept |
The headers that have been added in a key-value pair.
|
nodiscardnoexcept |
The host name to connect to.
|
nodiscardnoexcept |
The parameters that have been added in a key-value pair.
|
nodiscardnoexcept |
The optional password for authentication if it has been set. If no password is set, the optional will be empty.
|
nodiscardnoexcept |
The list of path segments for the URL. Path segments represent the individual parts of the URL path.
|
nodiscardnoexcept |
The optional port number for the network request.
|
nodiscardnoexcept |
The queries that have been added in a key-value pair.
|
nodiscardnoexcept |
The current URI scheme used in the network request.
RequestBuilder & drn::networking::RequestBuilder::setCredentials | ( | const ::QString & | username, |
const std::optional<::QString > & | password = std::nullopt ) |
Sets the credentials for authentication.
username | The username for authentication. |
password | The optional password for authentication. |
RequestBuilder & drn::networking::RequestBuilder::setFragment | ( | const ::QString & | fragment | ) |
Sets the fragment portion of the URL.
fragment | The fragment to set. |
RequestBuilder & drn::networking::RequestBuilder::setPort | ( | const std::uint16_t | port | ) |
Sets the port number.
port | The port number to use. |
|
nodiscardnoexcept |
The user-name used for authentication if it is set. If the user-name is not set, the returned optional will be empty.