Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::http::Client Class Reference

Asynchronous HTTP/1.1 and HTTP/2 client (libcurl's multi interface). More...

#include <Client.hpp>

Public Member Functions

 Client (ClientOptions options={})
 
 ~Client ()
 Requests still in flight complete with error "client shut down".
 
 Client (const Client &)=delete
 
Client & operator= (const Client &)=delete
 
void send (ClientRequest request, std::function< void(ClientResponse)> on_done)
 Starts request; on_done is called once, on the client's thread.
 
ClientSendAwaiter send_async (ClientRequest request)
 Awaitable form of send(); the coroutine resumes on the client's thread.
 
ClientResponse send_sync (ClientRequest request)
 Sends request and waits for the response, blocking the calling thread (for code that cannot be asynchronous).
 

Static Public Member Functions

static Client & shared ()
 A process-wide client, created on first use.
 

Private Attributes

std::unique_ptr< Impl > impl_
 

Detailed Description

Asynchronous HTTP/1.1 and HTTP/2 client (libcurl's multi interface).

One background thread drives every transfer, so many requests run at once without tying up worker threads, and connections are kept alive and reused between requests to the same host. Only http and https URLs are fetched, including on redirects, and TLS certificates are verified unless a request turns that off.

Completion callbacks, and coroutines resumed by send_async(), run on the client's thread: keep them short, and hand blocking work to a thread pool.

req.url = "https://api.example.com/items";
auto res = co_await http::Client::shared().send_async(req);
if (res.ok() && res.status == 200) { ... }
static Client & shared()
A process-wide client, created on first use.
ClientSendAwaiter send_async(ClientRequest request)
Awaitable form of send(); the coroutine resumes on the client's thread.
Definition Client.hpp:94
An outbound HTTP request for Client.
Definition Client.hpp:16
std::string url
http:// or https:// only
Definition Client.hpp:18

Constructor & Destructor Documentation

◆ Client() [1/2]

orbit::http::Client::Client ( ClientOptions  options = {})
explicit

◆ ~Client()

orbit::http::Client::~Client ( )

Requests still in flight complete with error "client shut down".

◆ Client() [2/2]

orbit::http::Client::Client ( const Client &  )
delete

Member Function Documentation

◆ operator=()

Client & orbit::http::Client::operator= ( const Client &  )
delete

◆ send()

void orbit::http::Client::send ( ClientRequest  request,
std::function< void(ClientResponse)>  on_done 
)

Starts request; on_done is called once, on the client's thread.

◆ send_async()

ClientSendAwaiter orbit::http::Client::send_async ( ClientRequest  request)
inline

Awaitable form of send(); the coroutine resumes on the client's thread.

◆ send_sync()

ClientResponse orbit::http::Client::send_sync ( ClientRequest  request)

Sends request and waits for the response, blocking the calling thread (for code that cannot be asynchronous).

Called from the client's own thread (inside a completion callback) it would wait forever, so it fails at once instead.

◆ shared()

static Client & orbit::http::Client::shared ( )
static

A process-wide client, created on first use.

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> orbit::http::Client::impl_
private

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