Raw client
The raw client allows custom HTTP or HTTPS requests to the Sitecore Content Hub, while still being authenticated and impersonated like any other action in the SDK. Any custom HTTP clients or delegating handlers are still used and events are still fired.
Built-in requests
The client supports the following requests:
-
GET
-
PUT
-
POST
-
DELETE
The following snippet will fetch an entity with id 1000, and directly read it as an EntityResource
which is the data model for the REST API.
HttpResponseMessage response = await MClient.Raw.GetAsync("http://localhost:8080/api/entities/1000");
response.EnsureSuccessStatusCode();
HttpResponseMessage resource = await response.Content.ReadAsJsonAsync<EntityResource> ();
The ReadAsJsonAsync
method can be imported from Stylelabs.M.Sdk.WebClient.Http
.
Custom headers can also be passed as a second (optional) parameter.
Full control over requests
Additionally, it is also possible to have full control over the request using the SendAsync
method, for example for verbs which are not built-in. This method requires a factory function that returns a HttpRequestMessage
. A factory function is needed so that the message can be retried on failures, because this requires a new message object.
No results from the raw client will be processed. No exceptions will be thrown when an unsuccessful status code is returned. This will need to be done manually. Some useful members on the HttpResponseMessage
are the EnsureSuccessStatusCode
method and IsSuccessStatusCode
property.