From 1d21cb3733f6953d0f14cb643827e71064d6d586 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 29 Dec 2023 09:30:51 +0100 Subject: [PATCH] Add extension method to get workflow instance ID This adds a new extension method in HttpResponseMessageExtensions class which retrieves the workflow instance ID from the response. It also includes a HeaderNames class to maintain the consistency of header names used by the Elsa API. --- .../Elsa.Api.Client/Extensions/HeaderExtensions.cs | 14 ++++++++++++++ src/clients/Elsa.Api.Client/Shared/HeaderNames.cs | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/clients/Elsa.Api.Client/Extensions/HeaderExtensions.cs create mode 100644 src/clients/Elsa.Api.Client/Shared/HeaderNames.cs diff --git a/src/clients/Elsa.Api.Client/Extensions/HeaderExtensions.cs b/src/clients/Elsa.Api.Client/Extensions/HeaderExtensions.cs new file mode 100644 index 0000000000..e23bafce7b --- /dev/null +++ b/src/clients/Elsa.Api.Client/Extensions/HeaderExtensions.cs @@ -0,0 +1,14 @@ +using Elsa.Api.Client.Shared; + +namespace Elsa.Api.Client.Extensions; + +/// +/// Contains extension methods for the class. +/// +public static class HttpResponseMessageExtensions +{ + /// + /// Gets the workflow instance ID from the response. + /// + public static string? GetWorkflowInstanceId(this HttpResponseMessage response) => response.Headers.TryGetValues(HeaderNames.WorkflowInstanceId, out var values) ? values.FirstOrDefault() : default; +} \ No newline at end of file diff --git a/src/clients/Elsa.Api.Client/Shared/HeaderNames.cs b/src/clients/Elsa.Api.Client/Shared/HeaderNames.cs new file mode 100644 index 0000000000..a3c26753c4 --- /dev/null +++ b/src/clients/Elsa.Api.Client/Shared/HeaderNames.cs @@ -0,0 +1,12 @@ +namespace Elsa.Api.Client.Shared; + +/// +/// Contains header names used by the Elsa API. +/// +public static class HeaderNames +{ + /// + /// The name of the header that contains the workflow instance ID. + /// + public const string WorkflowInstanceId = "x-elsa-workflow-instance-id"; +} \ No newline at end of file