HTTP Authentication

Passing an xxhr::Authentication is enough to transmit user and password information. In HTTP there are two ways : Basic and Digest authentication.

It is recommended to use authentication, even the Digest one only on a TLS connection.

Basic Authentication

In this example we query the Github REST search api, if you've setup 2-Factor Authentication on your github account you should use a github personal access token to test this example and use it in place of password.

Otherwise you'll get an xxhr::Response::status_code 404.

// For example connecting to the Github API v3 with your Github Credentials
GET("https://api.github.com/search/code"s,
Authentication{"username", "password"},
// Will be transmitted in cleartext base64 encoded, therefore the use of https is recommended.
Parameters{{"q", "authenticated search string"}},
on_response = [](auto&& resp) {
std::cout << resp.text;
});

Digest Authentication

To initiate a Digest authentication use in-place of xxhr::Authentication the xxhr::Digest parameter:

// For example connecting to the Github API v3 with your Github Credentials
GET("https://api.github.com/search/code"s,
Digest{"username", "password"},
// Will be transmitted as MD5 hash.
Parameters{{"q", "authenticated search string"}},
on_response = [](auto&& resp) {
std::cout << resp.text;
});