Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis Developer Reference
restincurl::Client Class Reference

#include <restincurl.h>

Collaboration diagram for restincurl::Client:
Collaboration graph

Public Member Functions

 Client (const bool init=true)
 
virtual ~Client ()
 
std::unique_ptr< RequestBuilderBuild ()
 
void CloseWhenFinished ()
 
void Close ()
 
void WaitForFinish ()
 
bool HaveWorker () const
 
size_t GetNumActiveRequests ()
 

Detailed Description

The high level abstraction of the Curl library.

An instance of a Client will, if asynchronous mode is enabled, create a worker-thread when the first request is made. This single worker-thread is then shared between all requests made for this client. When no requests are active, the thread will wait for a while (see RESTINCURL_IDLE_TIMEOUT_SEC), keeping libcurl's connection-cache warm, to serve new requests as efficiently as possible. When the idle time period expires, the thread will terminate and close the connection-cache associated with the client. If a new request is made later on, a new worker-thread will be created.

Constructor & Destructor Documentation

◆ Client()

restincurl::Client::Client ( const bool init = true)
inline

Constructor

Parameters
initSet to true if you need to initialize libcurl.

Libcurl require us to call an initialization method once, before using the library. If you use libcurl exclusively from RESTinCurl, init needs to be true (default). If you use RESTinCurl in a project that already initialize libcurl, you should pass false to the constructor.

RESTinCurl will only call libcurl's initialization once, no matter how many times you call the constructor. It's therefore safe to always use the default value when you want RESTinCurl to deal with libcurl's initialization.

References RESTINCURL_LOG.

◆ ~Client()

virtual restincurl::Client::~Client ( )
inlinevirtual

Destructor

The destructor will try to clean up resources (when in asynchronous mode) ant may wait for a little while for IO operations to stop and the worker-thread to finish.

This is to prevent your application for crashing if you exit the main thread while the worker-thread is still working and accessing memory own by the Client instance.

References RESTINCURL_LOG.

Member Function Documentation

◆ Build()

std::unique_ptr< RequestBuilder > restincurl::Client::Build ( )
inline

Build a request

Requests are "built" using a series of statements to fully express what you want to do and how you want RESTinCurl to do it.

Example

client.Build()->Get("https://api.example.com")
.AcceptJson()
.Header("X-Client", "restincurl")
.WithCompletion([&](const Result& result) {
// Do something
})
.Execute();
Definition restincurl.h:1656
std::unique_ptr< RequestBuilder > Build()
Definition restincurl.h:1720
Definition restincurl.h:241

References RESTINCURL_ENABLE_ASYNC.

◆ Close()

void restincurl::Client::Close ( )
inline

Close the client.

This method aborts any and all requests.

The worked-thread will exit shortly after this method is called, if it was running.

This method is only available when RESTINCURL_ENABLE_ASYNC is nonzero.

◆ CloseWhenFinished()

void restincurl::Client::CloseWhenFinished ( )
inline

Shut down the event-loop and clean up internal resources when all active and queued requests are done.

This method is only available when RESTINCURL_ENABLE_ASYNC is nonzero.

◆ GetNumActiveRequests()

size_t restincurl::Client::GetNumActiveRequests ( )
inline

Get the number of active / ongoing requests.

This method is only available when RESTINCURL_ENABLE_ASYNC is nonzero.

◆ HaveWorker()

bool restincurl::Client::HaveWorker ( ) const
inline

Check if the client instance has a worker-thread.

This method is only available when RESTINCURL_ENABLE_ASYNC is nonzero.

◆ WaitForFinish()

void restincurl::Client::WaitForFinish ( )
inline

Wait for the worker-thread to finish.

You should call Close() first.

This method is only available when RESTINCURL_ENABLE_ASYNC is nonzero.


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