| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::http_request Class Reference

A HTTP request. More...

`#include <queues.h>`

Collaboration diagram for dpp::http_request:
[legend]

## Public Member Functions

| http_request (const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata="", http_method method=m_get, const std::string &audit_reason="", const std::string &filename="", const std::string &filecontent="", const std::string &filemimetype="", const std::string &http_protocol="1.1")
| Constructor. When constructing one of these objects it should be passed to request_queue::post_request().
| http_request (const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata="", http_method method=m_get, const std::string &audit_reason="", const std::vector< std::string > &filename={}, const std::vector< std::string > &filecontent={}, const std::vector< std::string > &filemimetypes={}, const std::string &http_protocol="1.1")
| Constructor. When constructing one of these objects it should be passed to request_queue::post_request().
| http_request (const std::string &_url, http_completion_event completion, http_method method=m_get, const std::string &_postdata="", const std::string &_mimetype="text/plain", const std::multimap< std::string, std::string > &_headers={}, const std::string &http_protocol="1.1")
| Constructor. When constructing one of these objects it should be passed to request_queue::post_request().
| ~http_request ()
| Destroy the http request object.
void | complete (const http_request_completion_t &c)
| Call the completion callback, if the request is complete.
https_client * | get_client () const
| Get the HTTPS client used to perform this request, or nullptr if there is none.
bool | is_completed ()
| Returns true if the request is complete.
http_request_completion_t | run (class request_concurrency_queue *processor, class cluster *owner)
| Execute the HTTP request and mark the request complete.

## Public Attributes

std::string | endpoint
| Endpoint name e.g. /api/users.
std::vector< std::string > | file_content
| Upload file contents (binary).
std::vector< std::string > | file_mimetypes
| Upload file mime types. application/octet-stream if unspecified.
std::vector< std::string > | file_name
| Upload file name (server side).
http_method | method
| HTTP method for request.
std::string | mimetype
| Request mime type.
std::string | parameters
| Major and minor parameters.
std::string | postdata
| Postdata for POST and PUT.
std::string | protocol
| HTTP protocol.
std::string | reason
| Audit log reason for Discord requests, if non-empty.
std::multimap< std::string, std::string > | req_headers
| Request headers (non-discord requests only).
bool | waiting
| Waiting for rate limit to expire.

## Detailed Description

A HTTP request.

You should instantiate one of these objects via its constructor, and pass a pointer to it into an instance of request_queue. Although you can directly call the run() method of the object and it will make a HTTP call, be aware that if you do this, it will be a BLOCKING call (not asynchronous) and will not respect rate limits, as both of these functions are managed by the request_queue class.

## Constructor & Destructor Documentation

## ◆ http_request() [1/3]

dpp::http_request::http_request | ( | const std::string & | _endpoint,
|  | const std::string & | _parameters,
|  | http_completion_event | completion,
|  | const std::string & | _postdata = "",
|  | http_method | method = m_get,
|  | const std::string & | audit_reason = "",
|  | const std::string & | filename = "",
|  | const std::string & | filecontent = "",
|  | const std::string & | filemimetype = "",
|  | const std::string & | http_protocol = "1.1" )

Constructor. When constructing one of these objects it should be passed to request_queue::post_request().

Parameters

  _endpoint | The API endpoint, e.g. /api/guilds
  _parameters | Major and minor parameters for the endpoint e.g. a user id or guild id
  completion | completion event to call when done
  _postdata | Data to send in POST and PUT requests
  method | The HTTP method to use from dpp::http_method
  audit_reason | Audit log reason to send, empty to send none
  filename | The filename (server side) of any uploaded file
  filecontent | The binary content of any uploaded file for the request
  filemimetype | The MIME type of any uploaded file for the request
  http_protocol | HTTP protocol

## ◆ http_request() [2/3]

dpp::http_request::http_request | ( | const std::string & | _endpoint,
|  | const std::string & | _parameters,
|  | http_completion_event | completion,
|  | const std::string & | _postdata = "",
|  | http_method | method = m_get,
|  | const std::string & | audit_reason = "",
|  | const std::vector< std::string > & | filename = {},
|  | const std::vector< std::string > & | filecontent = {},
|  | const std::vector< std::string > & | filemimetypes = {},
|  | const std::string & | http_protocol = "1.1" )

Constructor. When constructing one of these objects it should be passed to request_queue::post_request().

Parameters

  _endpoint | The API endpoint, e.g. /api/guilds
  _parameters | Major and minor parameters for the endpoint e.g. a user id or guild id
  completion | completion event to call when done
  _postdata | Data to send in POST and PUT requests
  method | The HTTP method to use from dpp::http_method
  audit_reason | Audit log reason to send, empty to send none
  filename | The filename (server side) of any uploaded file
  filecontent | The binary content of any uploaded file for the request
  filemimetypes | The MIME type of any uploaded file for the request
  http_protocol | HTTP protocol

## ◆ http_request() [3/3]

dpp::http_request::http_request | ( | const std::string & | _url,
|  | http_completion_event | completion,
|  | http_method | method = m_get,
|  | const std::string & | _postdata = "",
|  | const std::string & | _mimetype = "text/plain",
|  | const std::multimap< std::string, std::string > & | _headers = {},
|  | const std::string & | http_protocol = "1.1" )

Constructor. When constructing one of these objects it should be passed to request_queue::post_request().

Parameters

  _url | Raw HTTP url
  completion | completion event to call when done
  method | The HTTP method to use from dpp::http_method
  _postdata | Data to send in POST and PUT requests
  _mimetype | POST data mime type
  _headers | HTTP headers to send
  http_protocol | HTTP protocol

## ◆ ~http_request()

dpp::http_request::~http_request | ( |  | ) |

Destroy the http request object.

## Member Function Documentation

## ◆ complete()

void dpp::http_request::complete | ( | const http_request_completion_t & | c | ) |

Call the completion callback, if the request is complete.

Parameters

  c | callback to call

## ◆ get_client()

https_client * dpp::http_request::get_client | ( |  | ) | const

Get the HTTPS client used to perform this request, or nullptr if there is none.

Returns
  https_client object

## ◆ is_completed()

bool dpp::http_request::is_completed | ( |  | ) |

Returns true if the request is complete.

Returns
  True if completed

## ◆ run()

http_request_completion_t dpp::http_request::run | ( | class request_concurrency_queue * | processor,
|  | class cluster * | owner )

Execute the HTTP request and mark the request complete.

Parameters

  processor | Request concurrency queue this request was created by
  owner | creating cluster

## Member Data Documentation

## ◆ endpoint

std::string dpp::http_request::endpoint

Endpoint name e.g. /api/users.

## ◆ file_content

std::vector<std::string> dpp::http_request::file_content

Upload file contents (binary).

## ◆ file_mimetypes

std::vector<std::string> dpp::http_request::file_mimetypes

Upload file mime types. application/octet-stream if unspecified.

## ◆ file_name

std::vector<std::string> dpp::http_request::file_name

Upload file name (server side).

## ◆ method

http_method dpp::http_request::method

HTTP method for request.

## ◆ mimetype

std::string dpp::http_request::mimetype

Request mime type.

## ◆ parameters

std::string dpp::http_request::parameters

Major and minor parameters.

## ◆ postdata

std::string dpp::http_request::postdata

Postdata for POST and PUT.

## ◆ protocol

std::string dpp::http_request::protocol

HTTP protocol.

## ◆ reason

std::string dpp::http_request::reason

Audit log reason for Discord requests, if non-empty.

## ◆ req_headers

std::multimap<std::string, std::string> dpp::http_request::req_headers

Request headers (non-discord requests only).

## ◆ waiting

bool dpp::http_request::waiting

Waiting for rate limit to expire.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0