D++ (DPP)  10.0.30
C++ Discord API Bot Library
Making Arbitrary HTTP Requests Using D++

If you wish to make arbitrary HTTP(S) requests to websites and APIs, e.g. to update statistics on bot lists, you can use code similar to the code below. You may pass any arbitrary POST data:

#include <dpp/dpp.h>
#include <iostream>
int main() {
dpp::cluster bot("token");
bot.on_ready([&bot](const dpp::ready_t& event) {
// Arbitrary post data as a string
std::string mypostdata = "{\"value\": 42}";
// Make a HTTP POST request. HTTP and HTTPS are supported here.
bot.request(
"http://www.somebotlist.com/api/servers", dpp::m_post, [](const dpp::http_request_completion_t & cc) {
// This callback is called when the HTTP request completes. See documentation of
// dpp::http_request_completion_t for information on the fields in the parameter.
std::cout << "I got reply: " << cc.body << " with HTTP status code: " << cc.status << "\n";
},
mypostdata,
"application/json",
{
{"Authorization", "Bearer tokengoeshere"}
}
);
});
bot.start(dpp::st_wait);
return 0;
}
dpp.h
dpp::st_wait
@ st_wait
Wait forever on a condition variable.
Definition: cluster.h:101
dpp::m_post
@ m_post
POST.
Definition: queues.h:210
main
int main()
Definition: soak.cpp:28
dpp::http_request_completion_t
The result of any HTTP request.
Definition: queues.h:130
dpp::utility::cout_logger
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout.
Definition: dispatcher.h:228
dpp::http_request_completion_t::status
uint16_t status
HTTP status.
Definition: queues.h:140
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:99
dpp::http_request_completion_t::body
std::string body
Reply body.
Definition: queues.h:181
dpp::ready_t
Session ready.
Definition: dispatcher.h:981