cofetch
Chainable, high-performance async HTTP client for C++ event loops
Loading...
Searching...
No Matches
cofetch::Client Class Reference

#include <cofetch.h>

Classes

class  RequestBuilder
 Fluent builder bound to this client. More...
 

Public Member Functions

 Client (net::io_context &io, size_t max_pooled_connections=kDefaultMaxPooledHandles)
 Construct a client driven by io.
 
 Client (const Client &)=delete
 
Clientoperator= (const Client &)=delete
 
 ~Client ()
 Destroy the client.
 
template<typename CompletionToken >
auto async_perform (Request req, CompletionToken &&token)
 Start a transfer described by req.
 
template<typename CompletionToken >
auto async_get (std::string url, CompletionToken &&token)
 
template<typename CompletionToken >
auto async_post (std::string url, std::string body, CompletionToken &&token)
 
RequestBuilder request (std::string url)
 Start a fluent request chain: request(url).body(...).post(token).
 
int pending_requests () const
 

Detailed Description

Constructor & Destructor Documentation

◆ Client() [1/2]

cofetch::Client::Client ( net::io_context &  io,
size_t  max_pooled_connections = kDefaultMaxPooledHandles 
)
inlineexplicit

Construct a client driven by io.

max_pooled_connections caps the idle easy handles kept for reuse; raise it for servers that keep many connections hot at once (default 64).

◆ Client() [2/2]

cofetch::Client::Client ( const Client )
delete

◆ ~Client()

cofetch::Client::~Client ( )
inline

Destroy the client.

Requests still in flight are dropped and their completion handlers are never invoked; prefer draining the io_context first.

Member Function Documentation

◆ async_get()

template<typename CompletionToken >
auto cofetch::Client::async_get ( std::string  url,
CompletionToken &&  token 
)
inline

◆ async_perform()

template<typename CompletionToken >
auto cofetch::Client::async_perform ( Request  req,
CompletionToken &&  token 
)
inline

Start a transfer described by req.

Completion signature is void(std::error_code, Response): the error_code carries the CURLcode (curl_category) for transport failures and is empty otherwise; HTTP error statuses are not transport failures (check Response::is_ok()).

If the completion handler has an associated cancellation slot (asio::bind_cancellation_slot, asio::cancel_after, co_spawn's cancellation state, ...), emitting cancellation aborts the transfer and the handler completes with asio::error::operation_aborted.

◆ async_post()

template<typename CompletionToken >
auto cofetch::Client::async_post ( std::string  url,
std::string  body,
CompletionToken &&  token 
)
inline

◆ operator=()

Client & cofetch::Client::operator= ( const Client )
delete

◆ pending_requests()

int cofetch::Client::pending_requests ( ) const
inline

◆ request()

RequestBuilder cofetch::Client::request ( std::string  url)
inline

Start a fluent request chain: request(url).body(...).post(token).

Examples
example_coroutine.cpp, example_fluent.cpp, example_http2.cpp, example_redirects.cpp, and example_tls.cpp.

The documentation for this class was generated from the following file: