Fluent builder for an outgoing HTTP request.
More...
#include <Malena/Engine/Networking/NetworkRequest.h>
Fluent builder for an outgoing HTTP request.
Construct a NetworkRequest with a URL, then chain method calls to configure headers, body, and other options before passing it to HttpClient::send().
.
body(R
"({"answer":"42"})")
Fluent builder for an outgoing HTTP request.
NetworkRequest & method(const std::string &m)
Override the HTTP method.
NetworkRequest & timeout(int seconds)
Set the request timeout in seconds. Default is 30 s.
NetworkRequest & body(const std::string &data, const std::string &contentType="application/json")
Set the request body.
NetworkRequest & bearerToken(const std::string &token)
Set the Authorization header to "Bearer <token>".
The result of an HTTP or WebSocket message.
- See also
- HttpClient, NetworkResponse
Definition at line 36 of file NetworkRequest.h.
◆ NetworkRequest()
| ml::NetworkRequest::NetworkRequest |
( |
const std::string & | url | ) |
|
|
explicit |
Construct a request for url.
The method defaults to GET. Add headers and a body before sending.
- Parameters
-
◆ basicAuth()
| NetworkRequest & ml::NetworkRequest::basicAuth |
( |
const std::string & | user, |
|
|
const std::string & | pass ) |
Set HTTP Basic Authentication credentials.
Encodes user and pass as Base64 and sets the Authorization header.
◆ bearerToken()
| NetworkRequest & ml::NetworkRequest::bearerToken |
( |
const std::string & | token | ) |
|
Set the Authorization header to "Bearer <token>".
- Parameters
-
| token | Bearer token string. |
◆ body() [1/2]
| NetworkRequest & ml::NetworkRequest::body |
( |
const nlohmann::json & | json | ) |
|
|
inline |
Set the request body from a nlohmann::json value.
Serialises json to a string and sets Content-Type to application/json automatically.
.
body({{
"answer",
"42"}, {
"questionId", 7}})
Definition at line 108 of file NetworkRequest.h.
◆ body() [2/2]
| NetworkRequest & ml::NetworkRequest::body |
( |
const std::string & | data, |
|
|
const std::string & | contentType = "application/json" ) |
Set the request body.
- Parameters
-
| data | Raw body string. |
| contentType | Value for the Content-Type header. Defaults to "application/json". |
◆ getBody()
| const std::string & ml::NetworkRequest::getBody |
( |
| ) |
const |
|
inlinenodiscard |
◆ getContentType()
| const std::string & ml::NetworkRequest::getContentType |
( |
| ) |
const |
|
inlinenodiscard |
◆ getHeaders()
| const std::unordered_map< std::string, std::string > & ml::NetworkRequest::getHeaders |
( |
| ) |
const |
|
inlinenodiscard |
◆ getMethod()
| const std::string & ml::NetworkRequest::getMethod |
( |
| ) |
const |
|
inlinenodiscard |
◆ getTimeout()
| int ml::NetworkRequest::getTimeout |
( |
| ) |
const |
|
inlinenodiscard |
◆ getUrl()
| const std::string & ml::NetworkRequest::getUrl |
( |
| ) |
const |
|
inlinenodiscard |
◆ header()
| NetworkRequest & ml::NetworkRequest::header |
( |
const std::string & | key, |
|
|
const std::string & | value ) |
Add or replace a request header.
- Parameters
-
| key | Header name (e.g. "X-Request-ID"). |
| value | Header value. |
◆ method()
Override the HTTP method.
Defaults to "GET". Common values: "POST", "PUT", "PATCH", "DELETE".
◆ timeout()
Set the request timeout in seconds. Default is 30 s.
- Parameters
-
| seconds | Maximum time to wait for a complete response. |
The documentation for this class was generated from the following file: