BaseConnection subclass that implements fetch(url, cb) via a background std::thread. More...
#include <threaded_connection.hpp>
Public Member Functions | |
| ~ThreadedConnection () override | |
| BaseConnection (const std::string &address, const std::map< std::string, std::string > &headerEntries) | |
| std::expected< std::string, HttpError > | fetch (const std::string &request) final |
| Perform a single HTTP request. | |
| std::expected< std::string, HttpError > | fetch (const std::string &request, IPaginationStrategy &strategy) final |
| Perform requests with automatic pagination. | |
| CancellationToken | fetch (const std::string &request, FetchCallback onSuccess, ErrorCallback onError={}) final |
| Perform an HTTP GET request asynchronously. | |
| CancellationToken | fetch (const std::string &request, IPaginationStrategy &strategy, BodyCallback onSuccess, ErrorCallback onError={}) final |
| Perform paginated requests asynchronously. | |
Public Member Functions inherited from cpp_restapi::BaseConnection | |
| BaseConnection (const std::string &address, const std::map< std::string, std::string > &headerEntries) | |
| const std::string & | url () const final |
| return API url | |
| std::expected< Response, HttpError > | fetchResponse (const std::string &url) final |
| Perform a single HTTP request returning the full response. | |
| std::string | get (const std::string &) final |
| perform a request to api | |
| virtual Response | fetchPage (const std::string &request)=0 |
Public Member Functions inherited from cpp_restapi::IConnection | |
| virtual | ~IConnection ()=default |
| virtual std::unique_ptr< ISseConnection > | subscribe (const std::string &request, EventCallback callback)=0 |
| Subscribe to an SSE endpoint. | |
Protected Member Functions | |
| void | fetchAsync (const std::string &fullUrl, CancellationToken cancel, FetchCallback onSuccess, ErrorCallback onError) override |
| void | waitForPending () |
Protected Member Functions inherited from cpp_restapi::BaseConnection | |
| const std::map< std::string, std::string > & | getHeaderEntries () const |
| const std::string & | address () const |
Additional Inherited Members | |
Public Types inherited from cpp_restapi::IConnection | |
| using | EventCallback = std::function<void(const SseEvent&)> |
| using | FetchCallback = std::function<void(Response)> |
| using | BodyCallback = std::function<void(std::string)> |
| using | ErrorCallback = std::function<void(HttpError)> |
BaseConnection subclass that implements fetch(url, cb) via a background std::thread.
Non-Qt backends (CppHttplib, Curl) inherit from this class to get a thread-based async fetch() without changes to their own code. The callback is invoked from the worker thread; callers are responsible for any required synchronisation.
The destructor blocks until all in-flight requests complete, so it is always safe to destroy the connection object.
|
override |
|
explicit |
|
finalvirtual |
Perform a single HTTP request.
| request | relative API path (e.g. "api/v1/disks") |
Returns std::unexpected(HttpError) when:
Reimplemented from cpp_restapi::BaseConnection.
|
finalvirtual |
Perform an HTTP GET request asynchronously.
Non-blocking. onSuccess is called with the full response when the request completes successfully; onError is called with an HttpError if the request fails. The callbacks may be invoked from a background thread (non-Qt backends) or from the Qt event-loop thread (Qt backend) — callers must handle thread-safety accordingly.
| request | relative API path (e.g. "users/octocat") |
| onSuccess | called with Response{body, headers, statusCode} on success |
| onError | called with an HttpError on failure (optional) |
Reimplemented from cpp_restapi::BaseConnection.
|
finalvirtual |
Perform requests with automatic pagination.
| request | relative API path |
| strategy | pagination strategy defining how to discover next page and merge results |
Reimplemented from cpp_restapi::BaseConnection.
|
finalvirtual |
Perform paginated requests asynchronously.
Non-blocking. Pages are fetched sequentially; once all pages have been collected the merged result is delivered via onSuccess. On any page failure onError is called and fetching stops.
| request | relative API path (e.g. "repos/owner/name/issues") |
| strategy | pagination strategy (next-page discovery and merge) |
| onSuccess | called with the merged body string on success |
| onError | called with an HttpError on failure (optional) |
Reimplemented from cpp_restapi::BaseConnection.
|
overrideprotectedvirtual |
Implements cpp_restapi::BaseConnection.
|
protected |
Block until all in-flight async requests complete. Derived classes whose fetchPage() override is virtual should call this in their destructor to prevent pure-virtual calls.