diff options
author | Juha Vuolle <[email protected]> | 2023-06-12 11:23:19 +0300 |
---|---|---|
committer | Juha Vuolle <[email protected]> | 2023-12-08 15:53:33 +0200 |
commit | e560adef213301318dcc13d4db155624846e0420 (patch) | |
tree | 237ffa17c837ee0f270885641b781d9bb47c6fd6 /src/network/doc/snippets/code | |
parent | f587ba1036164691a0981897397bdcc8f3472438 (diff) |
Add REST client convenience wrappers
[ChangeLog][QtNetwork][QRestAccessManager] Added new convenience
classes QRestAccessManager and QRestReply for typical RESTful
client application usage
Task-number: QTBUG-114637
Task-number: QTBUG-114701
Change-Id: I65057e56bf27f365b54bfd528565efd5f09386aa
Reviewed-by: MÃ¥rten Nordheim <[email protected]>
Reviewed-by: Mate Barany <[email protected]>
Reviewed-by: Marc Mutz <[email protected]>
Diffstat (limited to 'src/network/doc/snippets/code')
-rw-r--r-- | src/network/doc/snippets/code/src_network_access_qrestaccessmanager.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/network/doc/snippets/code/src_network_access_qrestaccessmanager.cpp b/src/network/doc/snippets/code/src_network_access_qrestaccessmanager.cpp new file mode 100644 index 00000000000..89c7348483c --- /dev/null +++ b/src/network/doc/snippets/code/src_network_access_qrestaccessmanager.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [0] +QRestReply *reply = manager->get(request); +QObject::connect(reply, &QRestReply::finished, this, &MyClass::handleFinished); +//! [0] + + +//! [1] +// With lambda +manager->get(request, this, [this](QRestReply *reply) { + if (reply->isSuccess()) { + // ... + } +}); +// With member function +manager->get(request, this, &MyClass::handleFinished); +//! [1] + + +//! [2] +QJsonObject myJson; +// ... +manager->post(request, myJson, this, [this](QRestReply *reply) { + if (!reply->isSuccess()) { + // ... + } + if (std::optional<QJsonObject> json = reply->json()) { + // use *json + } +}); +//! [2] + + +//! [3] +manager->get(request, this, [this](QRestReply *reply) { + if (!reply->isSuccess()) + // handle error + if (std::optional<QJsonObject> json = reply->json()) + // use *json +}); +//! [3] + + +//! [4] +manager->get(request, myData, this, [this](QRestReply *reply) { + if (reply->isSuccess()) + // ... +}); +//! [4] + + +//! [5] +manager->post(request, myData, this, [this](QRestReply *reply) { + if (reply->isSuccess()) + // ... +}); +//! [5] + + +//! [6] +manager->put(request, myData, this, [this](QRestReply *reply) { + if (reply->isSuccess()) + // ... +}); +//! [6] + + +//! [7] +manager->head(request, this, [this](QRestReply *reply) { + if (reply->isSuccess()) + // ... +}); +//! [7] + + +//! [8] +manager->deleteResource(request, this, [this](QRestReply *reply) { + if (reply->isSuccess()) + // ... +}); +//! [8] + |