Basic helper for REST API clients.
More...
#include <tsRestClient.h>
Basic helper for REST API clients.
◆ RestClient()
Constructor.
- Parameters
-
[in] | args | Initial REST operation arguments. This instance will keep a copy of it. |
[in,out] | report | Where to report errors. This instance will keep a reference to it. |
◆ setAcceptTypes()
void ts::RestClient::setAcceptTypes |
( |
const UString & |
types | ) |
|
|
inline |
Set the accepted MIME types for the response.
- Parameters
-
[in] | types | Accepted MIME type or comma-separated types. Typical values are u"*‍/*", u"text/plain", u"application/json", u"application/xml". |
◆ call()
Call a REST API.
- Parameters
-
[in] | api | Path of the API call. Concatenated with the RestArgs::api_root it is not empty. |
[in] | post_data | If not empty, the request is a POST with these data. |
- Returns
- True on success, false on error.
◆ httpStatus()
int ts::RestClient::httpStatus |
( |
| ) |
const |
|
inline |
Get the HTTP status code (200, 404, etc).
Valid after call().
- Returns
- The HTTP status code.
◆ responseHeaders()
Get all response headers.
Valid after call(), until next call() or this instance is destroyed.
- Returns
- A constant reference to a map of response headers.
◆ mimeType()
UString ts::RestClient::mimeType |
( |
bool |
simple = true , |
|
|
bool |
lowercase = true |
|
) |
| const |
|
inline |
Get the MIME type in the response headers.
Valid after call().
- Parameters
-
[in] | simple | If true, simple type name. If false, return the full specification with options. |
[in] | lowercase | Force lowercase in the result. |
- Returns
- The MIME type.
◆ response()
const ByteBlock & ts::RestClient::response |
( |
| ) |
const |
|
inline |
Get the response in binary format.
Valid after call(), until next call() or this instance is destroyed.
- Returns
- A constant reference to binary response.
◆ getResponseText()
void ts::RestClient::getResponseText |
( |
UString & |
response | ) |
const |
Get the response in text form (interpreted from UTF-8).
Valid after call().
- Parameters
-
[out] | response | Response in text form. All CR/LF are turned into simple LF. The last end-of-line, if any, is removed. |
◆ getResponseJSON()
Get the response in JSON form.
Valid after call().
- Parameters
-
[out] | value | Response in JSON form. |
- Returns
- True on success, false on error (typically when the returned data are not valid JSON).
The documentation for this class was generated from the following file: