26 template <
typename TResource>
36 m_client.GetDefaultRequestHeaders().Add(
"accept",
"application/json");
45 auto& headers = m_client.GetDefaultRequestHeaders();
46 headers.Remove(
"Authorization");
47 headers.Remove(
"authorization");
58 for (
int i = 0; i < len; ++i) {
59 arr[i] = credentials[i];
63 auto& headers = m_client.GetDefaultRequestHeaders();
64 headers.Remove(
"Authorization");
65 headers.Remove(
"authorization");
71 auto& headers = m_client.GetDefaultRequestHeaders();
72 headers.Remove(
"Authorization");
73 headers.Remove(
"authorization");
80 auto& headers = m_client.GetDefaultRequestHeaders();
81 headers.Remove(sName);
82 headers.Add(sName, sValue);
88 m_client.GetDefaultRequestHeaders().Remove(sName);
94 auto resp = m_client.Get(m_sBaseUrl);
95 resp->EnsureSuccessStatusCode();
97 return DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<DotNetDupe::System::Collections::Generic::List<TResource>>(body);
109 auto resp = m_client.Get(url);
110 resp->EnsureSuccessStatusCode();
112 return DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
121 auto resp = m_client.Post(m_sBaseUrl, content);
122 resp->EnsureSuccessStatusCode();
123 return resp->GetContent()->ReadAsString();
130 template <
typename TResult = TResource>
134 auto resp = m_client.Post(m_sBaseUrl, content);
135 resp->EnsureSuccessStatusCode();
137 return DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResult>(body);
152 auto resp = m_client.Put(url, content);
153 resp->EnsureSuccessStatusCode();
154 return resp->GetContent()->ReadAsString();
165 auto resp = m_client.Delete(url);
166 resp->EnsureSuccessStatusCode();
Defines common cross-platform macros, export decorators, and fundamental types.
Converts a base data type to another base data type, and encodes/decodes Base64 data.
Provides a base class for sending HTTP requests and receiving HTTP responses mirroring ....
Provides functionality to serialize objects to JSON strings and deserialize JSON strings into objects...
Represents a strongly typed list of objects that can be accessed by index mirroring ....
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Represents a strongly typed list of objects accessible by index.
static String ToBase64String(const Array< char > &inArray)
Sends HTTP requests and receives HTTP responses from a resource identified by a URI.
~RestClient() override=default
Virtual destructor.
void Delete(const DotNetDupe::System::String &sId)
Sends DELETE request targeting a specific resource ID.
DotNetDupe::System::Collections::Generic::List< TResource > GetAll()
Sends GET request to endpoint and deserializes JSON response into a List of models.
RestClient(const DotNetDupe::System::String &sBaseUrl)
Initializes a new instance of RestClient with a base resource endpoint URL.
DotNetDupe::System::String Put(const DotNetDupe::System::String &sId, const TResource &resource)
Sends PUT request updating a specific resource ID and returns raw response string.
void SetBasicAuthentication(const DotNetDupe::System::String &sUsername, const DotNetDupe::System::String &sPassword)
Sets Basic Authentication (username:password) encoded via Base64 for HTTP Authorization header (RFC 7...
TResult PostAndReturn(const TResource &resource)
Sends POST request with serialized resource and deserializes response into TResult.
DotNetDupe::System::String Post(const TResource &resource)
Sends POST request with serialized resource and returns raw string response body.
void AddDefaultRequestHeader(const DotNetDupe::System::String &sName, const DotNetDupe::System::String &sValue)
Adds a custom default request header sent with all HTTP calls.
void ClearAuthentication()
Clears custom authentication headers.
void SetBearerToken(const DotNetDupe::System::String &sToken)
Sets a Bearer token for the HTTP Authorization header (RFC 6750).
TResource Get(const DotNetDupe::System::String &sId)
Sends GET request for a specific entity ID and deserializes the JSON response.
void RemoveDefaultRequestHeader(const DotNetDupe::System::String &sName)
Removes a specific default request header.
Supports all classes in the DotNetDupe class hierarchy.
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
bool EndsWith(char ch, bool bIgnoreCase) const
static String Serialize(const T &value)
Converts the value of a type specified by a generic type parameter into a JSON string.