GETting Started

Download

Drop the following in your .nxxm/deps :

{
"daminetreg/xxhr" : { "@" : "v1.0.0" }
}

Include xxhr convenience header

The library is really lightweight, therefore it makes sense to include all definitions at once.

#include <xxhr/xxhr.hpp>

Supposed using declaration

All documentation in this library suppose the use at function scope of :

using namespace xxhr;

Select the type of HTTP Request

In a RESTful model the CRUD operations are the entrypoints of Requests, and so is the entrypoint of xxhr :

From there on, all goes asynchronous with the on_response continuation handler which expects a lambda or whatever Callable which accepts a Response.

To get started, nothing better than downloading the everlasting HTTP Request For Comment :

GET( "http://httpbin.org/anything"s,
on_response = [](auto&& resp) {
std::cout << resp.text;
}
);

Below HTTP it can go wrong

HTTP is the icing on the cake of network communications, there are alot of OSI layer below, that we shouldn't care of but which might prevent your app from running correctly.

Therefore you can check an xxhr::Response for the resp.error field :

GET( "http://httpbin.org/anything"s,
on_response = [](auto&& resp) {
if (!resp.error) {
std::cout << resp.text;
} else {
std::cout << resp.error;
}
}
);

users aren't patient

To avoid blocking your application with never ending HTTP requests you can specify an xxhr::Timeout, which will calls the on_response callback early with the xxhr::Error code : ErrorCode::TIMEDOUT.

GET(
"http://httpbin.org/anything"s,
Timeout{3s},
on_response = [](auto&& resp) {
if (resp.error.code == +ErrorCode::TIMEDOUT)
std::cout << "Timed out !\n";
}
);

For more details see Retry on failure

xxhr::on_response
constexpr make_handler_t< on_response_ > on_response
Continuation callback ( i.e. signature : void callback(xxhr::Response)) for the asynchronous HTTP ope...
Definition: handler.hpp:39
xxhr::GET
void GET(Ts &&... ts)
HTTP GET Request.
Definition: api.hpp:41
xxhr
main library namespace
Definition: api.hpp:20