1 #ifndef QTRESTCLIENT_RESTCLASS_H
2 #define QTRESTCLIENT_RESTCLASS_H
4 #include "QtRestClient/qtrestclient_global.h"
5 #include "QtRestClient/requestbuilder.h"
6 #include "QtRestClient/restreply.h"
7 #include "QtRestClient/restclient.h"
9 #ifndef Q_RESTCLIENT_NO_JSON_SERIALIZER
10 #include "QtRestClient/genericrestreply.h"
13 #include <QtCore/qobject.h>
17 class RestClassPrivate;
23 friend class RestClientPrivate;
51 RestReply *callRaw(
const QByteArray &verb,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {},
bool paramsAsBody =
false)
const;
55 RestReply *callRaw(
const QByteArray &verb,
const QUrl &relativeUrl,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {},
bool paramsAsBody =
false)
const;
56 RestReply *callRaw(
const QByteArray &verb,
const QUrl &relativeUrl,
const QCborValue &body,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {})
const;
57 RestReply *callRaw(
const QByteArray &verb,
const QUrl &relativeUrl,
const QJsonValue &body,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {})
const;
60 #ifndef Q_RESTCLIENT_NO_JSON_SERIALIZER
61 template<
typename DT = QObject*,
typename ET = QObject*>
64 GenericRestReply<DT, ET> *call(
const QByteArray &verb,
const QString &methodPath,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {},
bool paramsAsBody =
false)
const;
65 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
66 GenericRestReply<DT, ET> *call(
const QByteArray &verb,
const QString &methodPath,
const RO &body,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {})
const;
68 template<
typename DT = QObject*,
typename ET = QObject*>
69 GenericRestReply<DT, ET> *call(
const QByteArray &verb,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {},
bool paramsAsBody =
false)
const;
70 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
71 GenericRestReply<DT, ET> *call(
const QByteArray &verb,
const RO &body,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {})
const;
73 template<
typename DT = QObject*,
typename ET = QObject*>
74 GenericRestReply<DT, ET> *call(
const QByteArray &verb,
const QUrl &relativeUrl,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {},
bool paramsAsBody =
false)
const;
75 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
76 GenericRestReply<DT, ET> *call(
const QByteArray &verb,
const QUrl &relativeUrl,
const RO &body,
const QVariantHash ¶meters = {},
const HeaderHash &headers = {})
const;
81 template<
typename DT = QObject*,
typename ET = QObject*>
83 return call<DT, ET>(GetVerb, methodPath, parameters, headers);
85 template<
typename DT = QObject*,
typename ET = QObject*>
87 return call<DT, ET>(GetVerb, parameters, headers);
89 template<
typename DT = QObject*,
typename ET = QObject*>
91 return call<DT, ET>(GetVerb, relativeUrl, parameters, headers);
97 template<
typename DT = QObject*,
typename ET = QObject*>
99 return call<DT, ET>(PostVerb, methodPath, parameters, headers,
true);
101 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
103 return call<DT, ET>(PostVerb, methodPath, body, {}, headers);
106 template<
typename DT = QObject*,
typename ET = QObject*>
108 return call<DT, ET>(PostVerb, parameters, headers,
true);
110 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
112 return call<DT, ET>(PostVerb, body, {}, headers);
115 template<
typename DT = QObject*,
typename ET = QObject*>
117 return call<DT, ET>(PostVerb, relativeUrl, parameters, headers,
true);
119 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
121 return call<DT, ET>(PostVerb, relativeUrl, body, {}, headers);
127 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
129 return call<DT, ET>(PutVerb, methodPath, body, parameters, headers);
131 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
133 return call<DT, ET>(PutVerb, body, parameters, headers);
135 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
137 return call<DT, ET>(PutVerb, relativeUrl, body, parameters, headers);
143 template<
typename DT = QObject*,
typename ET = QObject*>
145 return call<DT, ET>(DeleteVerb, methodPath, parameters, headers);
147 template<
typename DT = QObject*,
typename ET = QObject*>
149 return call<DT, ET>(DeleteVerb, parameters, headers);
151 template<
typename DT = QObject*,
typename ET = QObject*>
153 return call<DT, ET>(DeleteVerb, relativeUrl, parameters, headers);
159 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
161 return call<DT, ET>(PatchVerb, methodPath, body, parameters, headers);
163 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
165 return call<DT, ET>(PatchVerb, body, parameters, headers);
167 template<
typename DT = QObject*,
typename ET = QObject*,
typename RO = QObject*>
169 return call<DT, ET>(PatchVerb, relativeUrl, body, parameters, headers);
175 template<
typename DT = QObject*,
typename ET = QObject*>
177 return call<DT, ET>(HeadVerb, methodPath, parameters, headers);
179 template<
typename DT = QObject*,
typename ET = QObject*>
181 return call<DT, ET>(HeadVerb, parameters, headers);
183 template<
typename DT = QObject*,
typename ET = QObject*>
185 return call<DT, ET>(HeadVerb, relativeUrl, parameters, headers);
191 virtual RequestBuilder builder()
const;
196 template<
typename... Args>
197 static QVariantHash concatParams(
const QString &key,
const QVariant &value, Args... parameters);
209 #ifdef QT_RESTCLIENT_USE_ASYNC
210 using CreateResult = std::variant<QNetworkReply*, QFuture<QNetworkReply*>>;
212 using CreateResult = std::variant<QNetworkReply*>;
215 CreateResult create(
const QByteArray &verb,
const QString &methodPath,
const QVariantHash ¶meters,
const HeaderHash &headers,
bool paramsAsBody)
const;
218 CreateResult create(
const QByteArray &verb,
const QVariantHash ¶meters,
const HeaderHash &headers,
bool paramsAsBody)
const;
221 CreateResult create(
const QByteArray &verb,
const QUrl &relativeUrl,
const QVariantHash ¶meters,
const HeaderHash &headers,
bool paramsAsBody)
const;
227 #define CONCAT_PARAMS QtRestClient::RestClass::concatParams
231 #ifndef Q_RESTCLIENT_NO_JSON_SERIALIZER
232 template<
typename DT,
typename ET>
235 return std::visit([&](
const auto &reply) {
237 }, create(verb, methodPath, parameters, headers, paramsAsBody));
240 template<
typename DT,
typename ET,
typename RO>
243 return std::visit([&](
auto bodyData) {
244 return std::visit([&](
const auto &reply) {
246 }, create(verb, methodPath, bodyData, parameters, headers));
250 template<
typename DT,
typename ET>
253 return std::visit([&](
const auto &reply) {
255 }, create(verb, parameters, headers, paramsAsBody));
258 template<
typename DT,
typename ET,
typename RO>
261 return std::visit([&](
auto bodyData) {
262 return std::visit([&](
const auto &reply) {
264 }, create(verb, bodyData, parameters, headers));
268 template<
typename DT,
typename ET>
271 return std::visit([&](
const auto &reply) {
273 }, create(verb, relativeUrl, parameters, headers, paramsAsBody));
276 template<
typename DT,
typename ET,
typename RO>
279 return std::visit([&](
auto bodyData) {
280 return std::visit([&](
const auto &reply) {
282 }, create(verb, relativeUrl, bodyData, parameters, headers));
287 template<
typename... Args>
291 hash.insert(key, value);
297 #endif // QTRESTCLIENT_RESTCLASS_H