Public Member Functions | List of all members
xxhr::Parameters Class Reference

Allows passing an initializer list of named HTTP Parameters that will be URL Encoded within the request URI or xxhr::Body ( i.e. In the form your/url?param=value). More...

Public Member Functions

void insert (const Parameter &parameter)
 adds another parameter
 

Detailed Description

xxhr::Parameters allows to provide a list of parameters that will be passed to the corresponding url.

GET parameters

Those parameters are appended URI Encoded to the URI, therefore note that sensitive information might be leaked to HTTP Proxy logs or other infrastructure in between xxhr and the server.

Let's query google search :

GET("https://www.google.com/search"s,
// This will end up in the URI as : https://www.google.com/search?q=...&ie=...
Parameters{
{"q", "xxhr c++ library"},
{"ie", "utf-8"},
},
on_response = [](auto&& resp) {
std::cout << "What Google finds about this library : " << resp.text;
});

POST form urlencoded Parameters

To perform an HTTP POST request with application/x-www-form-urlencoded parameters you can wrap Parameters into xxhr::Body.

In this context, you might also need to send URI xxhr::Parameters as in the example above. Therefore sending form-urlencoded parameter can be combined as follow :

POST("http://httpbin.org/post"s,
// This will end up in the URI as : http://httpbin.org/post?id=43&lang=en
Parameters{
{"id", "43"},
{"lang", "en"},
},
// While these params will be form-encoded parameters in the body
Body{
Parameters{
{"parameter_name_in_body", "xxhr c++ library"},
{"some_other_data", "As well in the HTTP body"},
}
},
on_response = [](auto&& resp) {
std::cout << "Reply from httpbin to see passed parameters : " << resp.text;
});

POST Raw payload

One can send a raw POST Payload without any encoding by instead passing a string for the xxhr::Body parameter :

// Here the body of the HTTP request is send as passed
Body{
"Big payload for some POST requests transmitted untouched"
},

Works for any HTTP verbs

Naturally all the above works for any HTTP verbs: POST, PUT, OPTIONS...


The documentation for this class was generated from the following file:
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::POST
void POST(Ts &&... ts)
HTTP POST Request.
Definition: api.hpp:47
xxhr::GET
void GET(Ts &&... ts)
HTTP GET Request.
Definition: api.hpp:41