cpp Rest API master
C++ library for REST API access with Qt, Curl and cpp-httplib backends
 
Loading...
Searching...
No Matches
qt_connection.hpp
Go to the documentation of this file.
1
2#ifndef CONNECTION_QT__HPP
3#define CONNECTION_QT__HPP
4
5#include <QNetworkRequest>
6#include <QSignalMapper>
7#include <QString>
8
9#include "base_connection.hpp"
10#include "cpp_restapi_export.h"
11
12
13class QNetworkAccessManager;
14
16{
17 class [[deprecated("Use createQtConnection() from <cpp_restapi/create_qt_connection.hpp>")]] CPP_RESTAPI_EXPORT Connection: public QObject, public BaseConnection
18 {
19 public:
20 Connection(QNetworkAccessManager &, const std::string& address, const std::map<std::string, std::string>& headerEntries);
21 Connection(const Connection &) = delete;
22
24
25 Connection& operator=(const Connection &) = delete;
26
27 using BaseConnection::fetch;
28
29 Response fetchPage(const std::string& request) override;
30 std::unique_ptr<ISseConnection> subscribe(const std::string& request, EventCallback callback) override;
31
32 protected:
33 void fetchAsync(const std::string& fullUrl, CancellationToken cancel, FetchCallback onSuccess, ErrorCallback onError) override;
34
35 private:
36 QNetworkAccessManager& m_networkManager;
37
38 QNetworkRequest prepareRequest();
39 };
40}
41
42#endif
base class with common parts for backend specific implementations
Definition base_connection.hpp:18
Definition qt_connection.hpp:18
void fetchAsync(const std::string &fullUrl, CancellationToken cancel, FetchCallback onSuccess, ErrorCallback onError) override
Connection(QNetworkAccessManager &, const std::string &address, const std::map< std::string, std::string > &headerEntries)
std::unique_ptr< ISseConnection > subscribe(const std::string &request, EventCallback callback) override
Subscribe to an SSE endpoint.
Connection(const Connection &)=delete
Response fetchPage(const std::string &request) override
Connection & operator=(const Connection &)=delete
Definition qt_connection.hpp:16
std::shared_ptr< std::atomic< bool > > CancellationToken
Token returned by asynchronous fetch(); set it to true to cancel the request.
Definition iconnection.hpp:33
std::function< void(Response)> FetchCallback
Definition iconnection.hpp:42
std::function< void(HttpError)> ErrorCallback
Definition iconnection.hpp:44
std::function< void(const SseEvent &)> EventCallback
Definition iconnection.hpp:41
HTTP response containing body, raw headers and the HTTP status code.
Definition iconnection.hpp:26