Interface representing connection with rest api server. More...
#include <iconnection.hpp>
Public Types | |
| 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)> |
Public Member Functions | |
| virtual | ~IConnection ()=default |
| virtual const std::string & | url () const =0 |
| return API url | |
| virtual std::expected< std::string, HttpError > | fetch (const std::string &request)=0 |
| Perform a single HTTP request. | |
| virtual std::expected< std::string, HttpError > | fetch (const std::string &request, IPaginationStrategy &strategy)=0 |
| Perform requests with automatic pagination. | |
| virtual std::expected< Response, HttpError > | fetchResponse (const std::string &url)=0 |
| Perform a single HTTP request returning the full response. | |
| virtual CancellationToken | fetch (const std::string &request, FetchCallback onSuccess, ErrorCallback onError={})=0 |
| Perform an HTTP GET request asynchronously. | |
| virtual CancellationToken | fetch (const std::string &request, IPaginationStrategy &strategy, BodyCallback onSuccess, ErrorCallback onError={})=0 |
| Perform paginated requests asynchronously. | |
| virtual std::unique_ptr< ISseConnection > | subscribe (const std::string &request, EventCallback callback)=0 |
| Subscribe to an SSE endpoint. | |
| virtual std::string | get (const std::string &request)=0 |
| perform a request to api | |
Interface representing connection with rest api server.
| using cpp_restapi::IConnection::BodyCallback = std::function<void(std::string)> |
| using cpp_restapi::IConnection::ErrorCallback = std::function<void(HttpError)> |
| using cpp_restapi::IConnection::EventCallback = std::function<void(const SseEvent&)> |
| using cpp_restapi::IConnection::FetchCallback = std::function<void(Response)> |
|
virtualdefault |
|
pure virtual |
Perform a single HTTP request.
| request | relative API path (e.g. "api/v1/disks") |
Returns std::unexpected(HttpError) when:
Implemented in cpp_restapi::BaseConnection, cpp_restapi::QtBackend::Connection, and cpp_restapi::ThreadedConnection.
|
pure virtual |
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) |
Implemented in cpp_restapi::BaseConnection, cpp_restapi::QtBackend::Connection, and cpp_restapi::ThreadedConnection.
|
pure virtual |
Perform requests with automatic pagination.
| request | relative API path |
| strategy | pagination strategy defining how to discover next page and merge results |
Implemented in cpp_restapi::BaseConnection, cpp_restapi::QtBackend::Connection, and cpp_restapi::ThreadedConnection.
|
pure virtual |
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) |
Implemented in cpp_restapi::BaseConnection, cpp_restapi::QtBackend::Connection, and cpp_restapi::ThreadedConnection.
|
pure virtual |
Perform a single HTTP request returning the full response.
| url | full URL to fetch |
Implemented in cpp_restapi::BaseConnection.
|
pure virtual |
perform a request to api
| request | api request. For example "users/SomeUserName/repos" |
Implemented in cpp_restapi::BaseConnection.
|
pure virtual |
Subscribe to an SSE endpoint.
| request | API endpoint path (e.g. "events" or "api/v1/events") |
| callback | function called for each received SSE event |
Implemented in cpp_restapi::CppHttplibBackend::Connection, cpp_restapi::CurlBackend::Connection, and cpp_restapi::QtBackend::Connection.
|
pure virtual |
return API url
Implemented in cpp_restapi::BaseConnection.