QtRestClient
3.0.0
A library for generic JSON-based REST-APIs, with a mechanism to map JSON to Qt objects
|
A class to handle generic replies for generic requests. More...
#include <genericrestreply.h>
Public Member Functions | |
GenericRestReply (QNetworkReply *networkReply, RestClient *client, QObject *parent=nullptr) | |
Creates a generic reply based on a network reply and for a client. More... | |
GenericRestReply (const QFuture< QNetworkReply * > &networkReplyFuture, RestClient *client, QObject *parent=nullptr) | |
Creates a generic reply based on a network reply future and for a client. More... | |
GenericRestReply< Paging< DataClassType >, ErrorClassType > * | onSucceeded (std::function< void(int, Paging< DataClassType >)> handler) |
Set a handler to be called if the request succeeded. More... | |
GenericRestReply< Paging< DataClassType >, ErrorClassType > * | onSucceeded (QObject *scope, std::function< void(int, Paging< DataClassType >)> handler) |
Set a handler to be called if the request succeeded. More... | |
GenericRestReply< Paging< DataClassType >, ErrorClassType > * | iterate (std::function< bool(DataClassType, qint64)> iterator, qint64 to=-1, qint64 from=0) |
shortcut to iterate over all elements via paging objects More... | |
GenericRestReply< Paging< DataClassType >, ErrorClassType > * | iterate (QObject *scope, std::function< bool(DataClassType, qint64)> iterator, qint64 to=-1, qint64 from=0) |
shortcut to iterate over all elements via paging objects More... | |
GenericRestReply< Paging< DataClassType >, ErrorClassType > * | onFailed (QObject *scope, std::function< void(int, ErrorClassType)> handler) final |
Set a handler to be called if the request failed. More... | |
GenericRestReply< Paging< DataClassType >, ErrorClassType > * | onError (QObject *scope, std::function< void(QString, int, RestReply::Error)> handler) final |
Set a handler to be called if a network error or json parse error occures. More... | |
Public Member Functions inherited from QtRestClient::GenericRestReplyBase< Paging< DataClassType >, ErrorClassType > | |
TInstance * | onFailed (std::function< void(int, ErrorClassType)> handler) |
Set a handler to be called if the request failed. More... | |
TInstance * | onSerializeException (std::function< void(QtJsonSerializer::Exception &)> handler) |
Set a handler to be called on deserialization exceptions. More... | |
TInstance * | onAllErrors (const std::function< void(QString, int, Error)> &handler, std::function< QString(ErrorClassType, int)> failureTransformer={}) |
Set a handler to be called if the request did not succeed. More... | |
TInstance * | onAllErrors (QObject *scope, const std::function< void(QString, int, Error)> &handler, std::function< QString(ErrorClassType, int)> failureTransformer={}) |
Set a handler to be called if the request did not succeed. More... | |
TInstance * | onCompleted (std::function< void(int)> handler) |
Set a handler to be called when the request was completed, regardless of success or failure. More... | |
TInstance * | onCompleted (QObject *scope, std::function< void(int)> handler) |
Set a handler to be called when the request was completed, regardless of success or failure. More... | |
TInstance * | onError (std::function< void(QString, int, Error)> handler) |
Set a handler to be called if a network error or json parse error occures. More... | |
TInstance * | makeAsync (QThreadPool *threadPool=QThreadPool::globalInstance()) |
WRITE accessor for RestReply::async. More... | |
TInstance * | disableAutoDelete () |
WRITE accessor for RestReply::autoDelete. More... | |
GenericRestReplyAwaitable< Paging< DataClassType >, ErrorClassType > | awaitable () |
Returns an awaitable object for this reply. | |
Public Member Functions inherited from QtRestClient::RestReply | |
RestReply (QNetworkReply *networkReply, QObject *parent=nullptr) | |
Creates a new reply based on a network reply. | |
RestReply (const QFuture< QNetworkReply * > &networkReplyFuture, QObject *parent=nullptr) | |
Creates a new reply based on a future network reply. | |
RestReply (QNetworkReply *networkReply, QThreadPool *asyncPool, QObject *parent=nullptr) | |
Creates a new reply based on a network reply and a threadpool. | |
RestReply (const QFuture< QNetworkReply * > &networkReplyFuture, QThreadPool *asyncPool, QObject *parent=nullptr) | |
Creates a new reply based on a future network reply and a threadpool. | |
template<typename TFn > | |
RestReply * | onSucceeded (TFn &&handler) |
Set a handler to be called if the request succeeded. More... | |
template<typename TFn > | |
RestReply * | onSucceeded (QObject *scope, TFn &&handler) |
Set a handler to be called if the request succeeded. More... | |
template<typename TFn > | |
RestReply * | onFailed (TFn &&handler) |
Set a handler to be called if the request failed. More... | |
template<typename TFn > | |
RestReply * | onFailed (QObject *scope, TFn &&handler) |
Set a handler to be called if the request failed. More... | |
template<typename TFn > | |
RestReply * | onCompleted (TFn &&handler) |
Set a handler to be called when the request was completed, regardless of success or failure. More... | |
template<typename TFn > | |
RestReply * | onCompleted (QObject *scope, TFn &&handler) |
Set a handler to be called when the request was completed, regardless of success or failure. More... | |
RestReply * | onError (std::function< void(QString, int, Error)> handler) |
Set a handler to be called if a network error or json parse error occures. More... | |
RestReply * | onError (QObject *scope, std::function< void(QString, int, Error)> handler) |
Set a handler to be called if a network error or json parse error occures. More... | |
template<typename TFn > | |
RestReply * | onAllErrors (const std::function< void(QString, int, Error)> &handler, TFn &&failureTransformer) |
Set a handler to be called if the request did not succeed. More... | |
template<typename TFn > | |
RestReply * | onAllErrors (QObject *scope, const std::function< void(QString, int, Error)> &handler, TFn &&failureTransformer) |
Set a handler to be called if the request did not succeed. More... | |
Q_INVOKABLE RestReply * | makeAsync (QThreadPool *threadPool=QThreadPool::globalInstance()) |
WRITE accessor for RestReply::async. | |
Q_INVOKABLE RestReply * | disableAutoDelete () |
WRITE accessor for RestReply::autoDelete. | |
bool | autoDelete () const |
READ accessor for RestReply::autoDelete. | |
bool | allowsEmptyReplies () const |
READ accessor for RestReply::allowEmptyReplies. | |
bool | isAsync () const |
READ accessor for RestReply::async. | |
Q_INVOKABLE QNetworkReply * | networkReply () const |
Returns the network reply associated with the rest reply. | |
RestReplyAwaitable | awaitable () |
Returns an awaitable object for this reply. | |
Public Member Functions inherited from QObject | |
virtual const QMetaObject * | metaObject () const const |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Q_DISABLE_COPY (Class) | |
Q_DISABLE_MOVE (Class) | |
Q_DISABLE_COPY_MOVE (Class) | |
T | qobject_cast (QObject *object) |
T | qobject_cast (const QObject *object) |
T | qFindChild (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QRegExp ®Exp) |
Q_CLASSINFO (Name, Value) | |
Q_INTERFACES (...) | |
Q_PROPERTY (...) | |
Q_ENUMS (...) | |
Q_FLAGS (...) | |
Q_ENUM (...) | |
Q_FLAG (...) | |
Q_ENUM_NS (...) | |
Q_FLAG_NS (...) | |
Q_OBJECT Q_OBJECT | |
Q_GADGET Q_GADGET | |
Q_NAMESPACE Q_NAMESPACE | |
Q_SIGNALS Q_SIGNALS | |
Q_SIGNAL Q_SIGNAL | |
Q_SLOTS Q_SLOTS | |
Q_SLOT Q_SLOT | |
Q_EMIT Q_EMIT | |
Q_INVOKABLE Q_INVOKABLE | |
Q_REVISION Q_REVISION | |
Q_SET_OBJECT_NAME (Object) | |
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
Additional Inherited Members | |
Public Types inherited from QtRestClient::GenericRestReplyBase< Paging< DataClassType >, ErrorClassType > | |
using | TInstance = GenericRestReply< Paging< DataClassType >, ErrorClassType > |
The specialized GenericRestReply that is associated with the reply base. | |
Public Types inherited from QtRestClient::RestReply | |
enum | Error { Error::Network, Error::Parser, Error::Failure, Error::Deserialization } |
Defines the different possible error types. More... | |
using | DataType = std::variant< std::nullopt_t, QCborValue, QJsonValue > |
Internal datatype that unites JSON and CBOR data in a typesafe union. | |
Public Slots inherited from QtRestClient::RestReply | |
void | abort () |
Aborts the request by calling QNetworkReply::abort. | |
void | retry () |
Tries to make the same request again, and reuses this rest reply. More... | |
void | retryAfter (std::chrono::milliseconds mSecs) |
Tries to make the same request again after a delay, and reuses this rest reply. More... | |
void | setAutoDelete (bool autoDelete) |
WRITE accessor for RestReply::autoDelete. | |
void | setAllowEmptyReplies (bool allowEmptyReplies) |
WRITE accessor for RestReply::allowEmptyReplies. | |
void | setAsync (bool async) |
WRITE accessor for RestReply::async. | |
Signals inherited from QtRestClient::RestReply | |
void | completed (int httpStatus, const DataType &reply, QPrivateSignal) |
Is emitted when the request completed, i.e. succeeded or failed. | |
void | succeeded (int httpStatus, const DataType &reply, QPrivateSignal) |
Is emitted when the request succeeded. | |
void | failed (int httpStatus, const DataType &reason, QPrivateSignal) |
Is emitted when the request failed. | |
void | error (const QString &errorString, int error, Error errorType, QPrivateSignal) |
Is emitted when a network or json parse error occured. | |
void | networkError (QNetworkReply::NetworkError error) |
Forwards QNetworkReply::error(QNetworkReply::NetworkError) | |
void | sslErrors (const QList< QSslError > &errors, bool &ignoreErrors) |
Forwards QNetworkReply::sslErrors. | |
void | downloadProgress (qint64 bytesReceived, qint64 bytesTotal) |
Forwards QNetworkReply::downloadProgress. | |
void | uploadProgress (qint64 bytesSent, qint64 bytesTotal) |
Forwards QNetworkReply::uploadProgress. | |
void | autoDeleteChanged (bool autoDelete, QPrivateSignal) |
NOTIFY accessor for RestReply::autoDelete. | |
void | allowEmptyRepliesChanged (bool allowEmptyReplies, QPrivateSignal) |
NOTIFY accessor for RestReply::allowEmptyReplies. | |
void | asyncChanged (bool async, QPrivateSignal) |
NOTIFY accessor for RestReply::async. | |
Static Public Member Functions inherited from QObject | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
Public Attributes inherited from QObject | |
typedef | QObjectList |
Protected Member Functions inherited from QObject | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
Properties inherited from QtRestClient::RestReply | |
bool | autoDelete |
Speciefies, whether the reply should be automatically deleted. More... | |
bool | allowEmptyReplies |
Speciefies, whether empty rest replies are allowed. More... | |
bool | async |
Specifies, whether the reply should be handled on a threadpool or not. More... | |
Properties inherited from QObject | |
objectName | |
A class to handle generic replies for generic requests.
DataClassType | The type of the positive result |
ErrorClassType | The type of the negative result |
This class is an extension to the RestReply, that includes deserialization into the reply. This way, you can directly use them without ever caring about the CBOR/JSON in the background.
Definition at line 133 of file genericrestreply.h.
QtRestClient::GenericRestReply< Paging< DataClassType >, ErrorClassType >::GenericRestReply | ( | QNetworkReply * | networkReply, |
RestClient * | client, | ||
QObject * | parent = nullptr |
||
) |
Creates a generic reply based on a network reply and for a client.
Definition at line 376 of file genericrestreply.h.
QtRestClient::GenericRestReply< Paging< DataClassType >, ErrorClassType >::GenericRestReply | ( | const QFuture< QNetworkReply * > & | networkReplyFuture, |
RestClient * | client, | ||
QObject * | parent = nullptr |
||
) |
Creates a generic reply based on a network reply future and for a client.
Definition at line 382 of file genericrestreply.h.
GenericRestReply< Paging< DataClassType >, ErrorClassType > * QtRestClient::GenericRestReply< Paging< DataClassType >, ErrorClassType >::iterate | ( | QObject * | scope, |
std::function< bool(DataClassType, qint64)> | iterator, | ||
qint64 | to = -1 , |
||
qint64 | from = 0 |
||
) |
shortcut to iterate over all elements via paging objects
scope | (optional) A scope to limit the callback to |
iterator | The iterator to be used by the Paging objects to iterate over the results |
to | The upper limit of how far the iteration should go (-1 means no limit) |
from | The lower limit from where the iteration should start |
This method is a shortcut that waits for the reply to succeed and then performs the iteration on the paging object. One advantage of this method is, that it automatically passes the error handlers of this reply onto the iteration. Check the Paging::iterate method for more details
The iterators parameters are:
true
if the iteration should continue, false
to cancel it prematurelyDefinition at line 468 of file genericrestreply.h.
GenericRestReply< Paging< DataClassType >, ErrorClassType > * QtRestClient::GenericRestReply< Paging< DataClassType >, ErrorClassType >::iterate | ( | std::function< bool(DataClassType, qint64)> | iterator, |
qint64 | to = -1 , |
||
qint64 | from = 0 |
||
) |
shortcut to iterate over all elements via paging objects
iterator | The iterator to be used by the Paging objects to iterate over the results |
to | The upper limit of how far the iteration should go (-1 means no limit) |
from | The lower limit from where the iteration should start |
This method is a shortcut that waits for the reply to succeed and then performs the iteration on the paging object. One advantage of this method is, that it automatically passes the error handlers of this reply onto the iteration. Check the Paging::iterate method for more details
The iterators parameters are:
true
if the iteration should continue, false
to cancel it prematurelyDefinition at line 442 of file genericrestreply.h.
|
finalvirtual |
Set a handler to be called if a network error or json parse error occures.
scope | A scope to limit the callback to |
handler | The function to be called on a network/json error |
The handlers arguments are:
Reimplemented from QtRestClient::GenericRestReplyBase< Paging< DataClassType >, ErrorClassType >.
Definition at line 484 of file genericrestreply.h.
|
finalvirtual |
Set a handler to be called if the request failed.
scope | A scope to limit the callback to |
handler | The function to be called on failure |
The handlers arguments are:
Reimplemented from QtRestClient::GenericRestReplyBase< Paging< DataClassType >, ErrorClassType >.
Definition at line 477 of file genericrestreply.h.
GenericRestReply< Paging< DataClassType >, ErrorClassType > * QtRestClient::GenericRestReply< Paging< DataClassType >, ErrorClassType >::onSucceeded | ( | QObject * | scope, |
std::function< void(int, Paging< DataClassType > | |||
) |
Set a handler to be called if the request succeeded.
scope | A scope to limit the callback to |
handler | The function to be called on success |
The handlers arguments are:
Definition at line 394 of file genericrestreply.h.
GenericRestReply< Paging< DataClassType >, ErrorClassType > * QtRestClient::GenericRestReply< Paging< DataClassType >, ErrorClassType >::onSucceeded | ( | std::function< void(int, Paging< DataClassType > | ) |
Set a handler to be called if the request succeeded.
handler | The function to be called on success |
The handlers arguments are:
Definition at line 388 of file genericrestreply.h.