Class EndpointRouteHelper
- Namespace
- Cratis.Arc.Http
- Assembly
- Cratis.Arc.Core.dll
Provides shared helpers for building endpoint routes and mapping result status codes.
public static class EndpointRouteHelper
- Inheritance
-
EndpointRouteHelper
- Inherited Members
Methods
BuildRouteUrl(ApiEndpointOptions, IEnumerable<string>, int, string, bool)
Builds a sanitized route URL from the given endpoint location and options.
public static string BuildRouteUrl(ApiEndpointOptions options, IEnumerable<string> location, int segmentsToSkip, string endpointName, bool includeNameInRoute)
Parameters
optionsApiEndpointOptionsThe ApiEndpointOptions.
locationIEnumerable<string>The namespace segments for the endpoint.
segmentsToSkipintThe number of leading namespace segments to skip.
endpointNamestringThe name of the endpoint (command type name or query name).
includeNameInRouteboolWhether to include the endpoint name as the last route segment.
Returns
- string
A sanitized, kebab-cased, lowercase route URL.
GetStatusCode(bool, bool, bool, bool)
Determines the HTTP status code for a result that has success, authorization, validation, and readiness state.
public static HttpStatusCode GetStatusCode(bool isSuccess, bool isAuthorized, bool isValid, bool isReady = true)
Parameters
isSuccessboolWhether the operation succeeded.
isAuthorizedboolWhether the operation was authorized.
isValidboolWhether the input was valid.
isReadyboolWhether the result is ready; defaults to true for results that have no readiness concept (for example command results).
Returns
- HttpStatusCode
The appropriate HttpStatusCode.
Remarks
A not-ready result (an observable query that has not yet produced its first result) maps to 202 Accepted
rather than a server error. Not-ready and error are mutually exclusive by construction — a not-ready result
carries no exception — so mapping readiness before the error fall-through cannot hide a genuine failure.
GroupByNamespace<T>(IEnumerable<T>, Func<T, IEnumerable<string>>, int)
Groups endpoint descriptors by their namespace key (location segments joined by '.').
public static IReadOnlyDictionary<string, List<T>> GroupByNamespace<T>(IEnumerable<T> endpoints, Func<T, IEnumerable<string>> locationSelector, int segmentsToSkip)
Parameters
endpointsIEnumerable<T>The endpoints to group.
locationSelectorFunc<T, IEnumerable<string>>A function to get the location segments from an endpoint.
segmentsToSkipintThe number of leading namespace segments to skip.
Returns
- IReadOnlyDictionary<string, List<T>>
A dictionary mapping namespace keys to lists of endpoints.
Type Parameters
TThe type of endpoint descriptor.
ShouldIncludeNameInRoute<T>(bool, IEnumerable<string>, IReadOnlyDictionary<string, List<T>>)
Determines whether the endpoint name should be included in the route, based on the configured option and whether there are conflicting endpoints in the same namespace.
public static bool ShouldIncludeNameInRoute<T>(bool includeNameOption, IEnumerable<string> location, IReadOnlyDictionary<string, List<T>> endpointsByNamespace)
Parameters
includeNameOptionboolThe configured option for including the name (e.g. IncludeCommandNameInRoute).
locationIEnumerable<string>The namespace segments for the endpoint.
endpointsByNamespaceIReadOnlyDictionary<string, List<T>>The endpoints grouped by namespace key.
Returns
- bool
True if the endpoint name should be included in the route.
Type Parameters
TThe type of endpoint descriptor (command handler, query performer, etc.).