cpp Rest API master
C++ library for REST API access with Qt, Curl and cpp-httplib backends
 
Loading...
Searching...
No Matches
cpp_restapi Namespace Reference

Namespaces

namespace  CppHttplibBackend
 
namespace  CurlBackend
 
namespace  detail
 
namespace  GitHub
 
namespace  QtBackend
 

Classes

class  BaseConnection
 base class with common parts for backend specific implementations More...
 
struct  Detached
 Fire-and-forget coroutine wrapper. More...
 
struct  HttpError
 Represents an HTTP or network-level error. More...
 
struct  IConnection
 Interface representing connection with rest api server. More...
 
struct  IPaginationStrategy
 Interface for pagination strategies. More...
 
struct  ISseConnection
 Interface for SSE (Server-Sent Events) connections. More...
 
class  LinkHeaderPaginationStrategy
 Pagination strategy using RFC 5988 Link headers. More...
 
struct  Response
 HTTP response containing body, raw headers and the HTTP status code. More...
 
struct  SseEvent
 Represents a single Server-Sent Event. More...
 
class  SseParser
 Incremental parser for Server-Sent Events stream. More...
 
class  ThreadedConnection
 BaseConnection subclass that implements fetch(url, cb) via a background std::thread. More...
 

Typedefs

using CancellationToken = std::shared_ptr<std::atomic<bool>>
 Token returned by asynchronous fetch(); set it to true to cancel the request.
 

Functions

detail::FetchAwaitable coFetch (IConnection &connection, const std::string &request)
 Asynchronously fetch a single resource.
 
detail::PaginatedFetchAwaitable coFetch (IConnection &connection, const std::string &request, IPaginationStrategy &strategy)
 Asynchronously fetch with pagination.
 
CPP_RESTAPI_EXPORT std::unique_ptr< IConnectioncreateCppHttplibConnection (const std::string &address, const std::map< std::string, std::string > &headerEntries)
 Create a connection using the cpp-httplib backend.
 
CPP_RESTAPI_EXPORT std::unique_ptr< IConnectioncreateCurlConnection (const std::string &address, const std::map< std::string, std::string > &headerEntries)
 Create a connection using the libcurl backend.
 
CPP_RESTAPI_EXPORT std::unique_ptr< IConnectioncreateQtConnection (QNetworkAccessManager &manager, const std::string &address, const std::map< std::string, std::string > &headerEntries)
 Create a connection using the Qt backend.
 

Typedef Documentation

◆ CancellationToken

using cpp_restapi::CancellationToken = std::shared_ptr<std::atomic<bool>>

Token returned by asynchronous fetch(); set it to true to cancel the request.

Function Documentation

◆ coFetch() [1/2]

detail::FetchAwaitable cpp_restapi::coFetch ( IConnection & connection,
const std::string & request )
inline

Asynchronously fetch a single resource.

Returns an awaitable — use with co_await:

auto result = co_await coFetch(connection, "users/1");
if (result)
std::cout << result->body;
detail::FetchAwaitable coFetch(IConnection &connection, const std::string &request)
Asynchronously fetch a single resource.
Definition coroutine.hpp:99

◆ coFetch() [2/2]

detail::PaginatedFetchAwaitable cpp_restapi::coFetch ( IConnection & connection,
const std::string & request,
IPaginationStrategy & strategy )
inline

Asynchronously fetch with pagination.

Returns an awaitable — use with co_await:

auto result = co_await coFetch(connection, "repos/owner/repo/issues", strategy);
Pagination strategy using RFC 5988 Link headers.
Definition link_header_pagination_strategy.hpp:18

◆ createCppHttplibConnection()

CPP_RESTAPI_EXPORT std::unique_ptr< IConnection > cpp_restapi::createCppHttplibConnection ( const std::string & address,
const std::map< std::string, std::string > & headerEntries )

Create a connection using the cpp-httplib backend.

Parameters
addressbase URL of the API (e.g. "https://api.github.com")
headerEntriesHTTP headers added to every request
Returns
owning pointer to the connection

◆ createCurlConnection()

CPP_RESTAPI_EXPORT std::unique_ptr< IConnection > cpp_restapi::createCurlConnection ( const std::string & address,
const std::map< std::string, std::string > & headerEntries )

Create a connection using the libcurl backend.

Parameters
addressbase URL of the API (e.g. "https://api.github.com")
headerEntriesHTTP headers added to every request
Returns
owning pointer to the connection

◆ createQtConnection()

CPP_RESTAPI_EXPORT std::unique_ptr< IConnection > cpp_restapi::createQtConnection ( QNetworkAccessManager & manager,
const std::string & address,
const std::map< std::string, std::string > & headerEntries )

Create a connection using the Qt backend.

Parameters
managerQt network access manager (must outlive the connection)
addressbase URL of the API (e.g. "https://api.github.com")
headerEntriesHTTP headers added to every request
Returns
owning pointer to the connection