aboutsummaryrefslogtreecommitdiff
path: root/lib/Net.Rest.Client/src
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-08-27 14:14:51 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-08-27 14:14:51 -0400
commit87df3ec1f0f87167853b197f66cefb48855df9ac (patch)
tree01f386c74e314470a97722e69b6748cf4cb4154a /lib/Net.Rest.Client/src
parentf541b853c738a076d2a85ef6b269c1b140353b85 (diff)
spelling, and tiny tweaks
Diffstat (limited to 'lib/Net.Rest.Client/src')
-rw-r--r--lib/Net.Rest.Client/src/Construction/Extensions.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/Net.Rest.Client/src/Construction/Extensions.cs b/lib/Net.Rest.Client/src/Construction/Extensions.cs
index bbc8b1d..ca0873b 100644
--- a/lib/Net.Rest.Client/src/Construction/Extensions.cs
+++ b/lib/Net.Rest.Client/src/Construction/Extensions.cs
@@ -76,6 +76,45 @@ namespace VNLib.Net.Rest.Client.Construction
}
/// <summary>
+ /// Executes a request against the site by sending the request model parameter. An <see cref="IRestEndpointAdapter{TModel}"/> must be
+ /// defined to handle requests of the given model type.
+ /// </summary>
+ /// <typeparam name="TModel"></typeparam>
+ /// <typeparam name="TJson">The response entity type</typeparam>
+ /// <param name="site"></param>
+ /// <param name="entity">The request entity model to send to the server</param>
+ /// <param name="cancellation">A token to cancel the operation</param>
+ /// <returns>A task that resolves the response message with json resonse support</returns>
+ public static async Task<RestResponse<TJson>> ExecuteAsync<TModel, TJson>(this IRestSiteAdapter site, TModel entity, CancellationToken cancellation = default)
+ {
+ //Get the adapter for the model
+ IRestEndpointAdapter<TModel> adapter = site.GetAdapter<TModel>();
+
+ //Get new request on adapter
+ RestRequest request = adapter.GetRequest(entity);
+
+ //Wait to exec operations if needed
+ await site.WaitAsync(cancellation);
+
+ RestResponse<TJson> response;
+
+ //Get rest client
+ using (ClientContract contract = site.GetClient())
+ {
+ //Exec response
+ response = await contract.Resource.ExecuteAsync<TJson>(request, cancellation);
+ }
+
+ //Site handler should not cause an exception
+ site.OnResponse(response);
+
+ //invoke response handlers
+ adapter.OnResponse(entity, response);
+
+ return response;
+ }
+
+ /// <summary>
/// Executes a request using a model that defines its own endpoint information, on the current site and returns the response
/// </summary>
/// <typeparam name="TModel">The request model type</typeparam>