AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::Call< Codecs > Class Template Reference

#include <client.hpp>

Collaboration diagram for anch::rest::Call< Codecs >:

Public Member Functions

 Call (anch::rest::Client &client, anch::rest::Request request)
Call & header (std::string_view name, std::string_view value) &
Call && header (std::string_view name, std::string_view value) &&
template<anch::rest::ParameterValue T>
Call & query (std::string_view name, const T &value) &
template<anch::rest::ParameterValue T>
Call && query (std::string_view name, const T &value) &&
template<typename C>
Call< Codecs..., C > accept () &&
template<typename C, typename T>
Call & body (const T &value) &
template<typename C, typename T>
Call && body (const T &value) &&
Call & body (std::string content, std::string_view contentType) &
Call && body (std::string content, std::string_view contentType) &&
Call & body (std::unique_ptr< std::istream > input, std::string_view contentType, std::optional< std::uint64_t > size=std::nullopt) &
Call && body (std::unique_ptr< std::istream > input, std::string_view contentType, std::optional< std::uint64_t > size=std::nullopt) &&
Call & body (anch::rest::RawBody raw) &
Call && body (anch::rest::RawBody raw) &&
anch::rest::Response send () &&
void execute () &&
template<typename T>
T as () &&
anch::rest::Request & getRequest () noexcept

Friends

template<typename...>
class Call

Detailed Description

template<typename... Codecs>
class anch::rest::Call< Codecs >

Request being built by Client .
Accepted codecs are part of the type: accept adds a codec and as deserializes the response with the accepted codec matching its Content-Type :

Pet pet = client.get("/pets/{id}", 42).accept<anch::codec::Json>().as<Pet>(); // HttpError when status >= 400

A call is sent once: send , execute and as are called on rvalues.

Template Parameters
Codecsthe accepted codecs
Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ Call()

template<typename... Codecs>
anch::rest::Call< Codecs >::Call ( anch::rest::Client & client,
anch::rest::Request request )

Call constructor

Parameters
clientthe client
requestthe request

Member Function Documentation

◆ accept()

template<typename... Codecs>
template<typename C>
Call< Codecs..., C > anch::rest::Call< Codecs >::accept ( ) &&

Accept codec media type (added to Accept header)

Template Parameters
Cthe codec
Returns
the call with this codec
Here is the call graph for this function:

◆ as()

template<typename... Codecs>
template<typename T>
T anch::rest::Call< Codecs >::as ( ) &&

Send request and deserialize response with the accepted codec matching its Content-Type

Template Parameters
Tthe result type (default constructible)
Returns
the response value
Exceptions
anch::rest::HttpErrorwhen status is an error (>= 400)
anch::rest::TransportErrorwhen request fails
std::runtime_errorwhen response content type is not accepted
std::exceptioncodec errors

◆ body() [1/8]

template<typename... Codecs>
Call & anch::rest::Call< Codecs >::body ( anch::rest::RawBody raw) &

Set raw body (see above)

Parameters
rawthe raw body
Returns
this
Here is the call graph for this function:

◆ body() [2/8]

template<typename... Codecs>
Call && anch::rest::Call< Codecs >::body ( anch::rest::RawBody raw) &&

Set raw body (see above)

Parameters
rawthe raw body
Returns
this
Here is the call graph for this function:

◆ body() [3/8]

template<typename... Codecs>
template<typename C, typename T>
Call & anch::rest::Call< Codecs >::body ( const T & value) &

Set body serialized with codec (Content-Type is the codec media type)

Template Parameters
Cthe codec
Parameters
valuethe body value
Returns
this
Here is the call graph for this function:

◆ body() [4/8]

template<typename... Codecs>
template<typename C, typename T>
Call && anch::rest::Call< Codecs >::body ( const T & value) &&

Set body serialized with codec (Content-Type is the codec media type)

Template Parameters
Cthe codec
Parameters
valuethe body value
Returns
this
Here is the call graph for this function:

◆ body() [5/8]

template<typename... Codecs>
Call & anch::rest::Call< Codecs >::body ( std::string content,
std::string_view contentType ) &

Set body content

Parameters
contentthe body content
contentTypethe content type
Returns
this
Here is the call graph for this function:

◆ body() [6/8]

template<typename... Codecs>
Call && anch::rest::Call< Codecs >::body ( std::string content,
std::string_view contentType ) &&

Set body content

Parameters
contentthe body content
contentTypethe content type
Returns
this
Here is the call graph for this function:

◆ body() [7/8]

template<typename... Codecs>
Call & anch::rest::Call< Codecs >::body ( std::unique_ptr< std::istream > input,
std::string_view contentType,
std::optional< std::uint64_t > size = std::nullopt ) &

Set body stream: it is read by the transport when the request is sent (with a size, the libcurl transport streams it: large bodies are not loaded in memory)

Parameters
inputthe body stream
contentTypethe content type
sizethe body size ( Content-Length ), empty when unknown
Returns
this
Here is the call graph for this function:

◆ body() [8/8]

template<typename... Codecs>
Call && anch::rest::Call< Codecs >::body ( std::unique_ptr< std::istream > input,
std::string_view contentType,
std::optional< std::uint64_t > size = std::nullopt ) &&

Set body stream (see above)

Parameters
inputthe body stream
contentTypethe content type
sizethe body size ( Content-Length ), empty when unknown
Returns
this
Here is the call graph for this function:

◆ execute()

template<typename... Codecs>
void anch::rest::Call< Codecs >::execute ( ) &&

Send request and check response status

Exceptions
anch::rest::HttpErrorwhen status is an error (>= 400)
anch::rest::TransportErrorwhen request fails

◆ getRequest()

template<typename... Codecs>
anch::rest::Request & anch::rest::Call< Codecs >::getRequest ( )
noexcept

Request getter

Returns
the request

◆ header() [1/2]

template<typename... Codecs>
Call & anch::rest::Call< Codecs >::header ( std::string_view name,
std::string_view value ) &

Set request header

Parameters
namethe header name
valuethe header value
Returns
this
Here is the call graph for this function:

◆ header() [2/2]

template<typename... Codecs>
Call && anch::rest::Call< Codecs >::header ( std::string_view name,
std::string_view value ) &&

Set request header

Parameters
namethe header name
valuethe header value
Returns
this
Here is the call graph for this function:

◆ query() [1/2]

template<typename... Codecs>
Call & anch::rest::Call< Codecs >::query ( std::string_view name,
const T & value ) &

Add query parameter (it is encoded)

Parameters
namethe parameter name
valuethe parameter value
Returns
this
Here is the call graph for this function:

◆ query() [2/2]

template<typename... Codecs>
Call && anch::rest::Call< Codecs >::query ( std::string_view name,
const T & value ) &&

Add query parameter (it is encoded)

Parameters
namethe parameter name
valuethe parameter value
Returns
this
Here is the call graph for this function:

◆ send()

template<typename... Codecs>
anch::rest::Response anch::rest::Call< Codecs >::send ( ) &&

Send request

Returns
the response, whatever its status
Exceptions
anch::rest::TransportErrorwhen request fails

◆ Call

template<typename... Codecs>
template<typename...>
friend class Call
friend

Calls with other codecs are friends (accept )


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