Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_network_access_qnetworkrequestfactory.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3using namespace Qt::StringLiterals;
4
6// Instantiate a factory somewhere suitable in the application
7QNetworkRequestFactory api{{"https://example.com/v1"_L1}};
8
9// Set bearer token
10api.setBearerToken("my_token");
11
12// Issue requests (reply handling omitted for brevity)
13manager.get(api.createRequest("models"_L1)); // https://example.com/v1/models
14// The conventional leading '/' for the path can be used as well
15manager.get(api.createRequest("/models"_L1)); // https://example.com/v1/models
17
18
20// Here the API version v2 is used as the base path:
21QNetworkRequestFactory api{{"https://example.com/v2"_L1}};
22// ...
23manager.get(api.createRequest("models"_L1)); // https://example.com/v2/models
24// Equivalent with a leading '/'
25manager.get(api.createRequest("/models"_L1)); // https://example.com/v2/models
27
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
Convenience class for grouping remote server endpoints that share common network request properties.
Q_NETWORK_EXPORT void setBearerToken(const QByteArray &token)
Sets the bearer token to token.
Q_NETWORK_EXPORT QNetworkRequest createRequest() const
Returns a QNetworkRequest.
QNetworkAccessManager manager
QNetworkRequestFactory api
[0]