API reference — HTTP & web

Nuvora.Nexus.Relay.Web

Web API Utilities for Nuvora Nexus Relay

dotnet add package Nuvora.Nexus.Relay.Web

Nuvora.Nexus.Relay.Web

AdminAreaParameterTransformer

public class AdminAreaParameterTransformer : IOutboundParameterTransformer

Rewrites controller names with an Admin prefix into the admin area path: the leading Admin (matched case-insensitively, consistent with the detection check) is stripped and the remainder is prefixed with admin/ (e.g. AdminUsers => admin/Users). Only the prefix is removed — later occurrences of “Admin” in the name are preserved.

Constructors

AdminAreaParameterTransformer(ILogger logger)

Rewrites controller names with an Admin prefix into the admin area path: the leading Admin (matched case-insensitively, consistent with the detection check) is stripped and the remainder is prefixed with admin/ (e.g. AdminUsers => admin/Users). Only the prefix is removed — later occurrences of “Admin” in the name are preserved.

Methods

string? TransformOutbound(object? value)

Transforms the specified route value to a string for inclusion in a URI.

CompositeParameterTransformer

public class CompositeParameterTransformer : IOutboundParameterTransformer

Chains multiple IOutboundParameterTransformers, feeding each transformer’s output into the next. A null intermediate result short-circuits the chain and returns null, matching the IOutboundParameterTransformer contract (no NREs on transformers that do not accept null).

Constructors

CompositeParameterTransformer(ILogger logger, params IOutboundParameterTransformer[] transformers)

Methods

string? TransformOutbound(object? value)

Transforms the specified route value to a string for inclusion in a URI.

ExceptionHandlingExtensions

public static class ExceptionHandlingExtensions

Extension methods for registering exception handling services and middleware

Methods

static IApplicationBuilder UseRelayExceptionHandling(this IApplicationBuilder app)

Adds Relay exception handling middleware to the application pipeline Should be called early in the pipeline, after routing but before authorization

static IServiceCollection AddRelayExceptionHandling(this IServiceCollection services, Action<ExceptionHandlingOptions>? configure = null)

Adds Relay exception handling services to the service collection

SlugifyParameterTransformer

public class SlugifyParameterTransformer : IOutboundParameterTransformer

Transforms PascalCase route values into kebab-case slugs (e.g. LoanProviders => loan-providers). Returns null for null values, matching the IOutboundParameterTransformer contract.

Methods

string? TransformOutbound(object? value)

Transforms the specified route value to a string for inclusion in a URI.

Nuvora.Nexus.Relay.Web.ExceptionHandling

DefaultExceptionMapper

public class DefaultExceptionMapper : IExceptionMapper

Default implementation of exception mapper

Constructors

DefaultExceptionMapper(ExceptionHandlingOptions options)

Methods

(int StatusCode, string Type, string Title) Map(Exception exception)

Maps an exception to HTTP status code, problem type, and title

bool IsSafeToExposeMessage(Exception exception)

Known-safe exception families whose Exception.Message is written for clients and may be exposed in ProblemDetails even when ExceptionHandlingOptions.IncludeExceptionDetails is disabled: the RelayException hierarchy, the Auth module’s Unauthorized/Forbidden exceptions (matched by full type name, like DefaultExceptionMapper.Map), and the pipeline’s validation exception. Anything else (e.g. a bare ArgumentException mapped to 4xx) may leak internals and gets a generic detail message instead.

ExceptionHandlingOptions

public class ExceptionHandlingOptions

Configuration options for exception handling

Properties

Dictionary<Type, (int StatusCode, string Type, string Title)>? CustomExceptionMappings { get; set; }

Custom exception mappings for service-specific exceptions Key: Exception type, Value: (statusCode, type, title)

bool IncludeExceptionDetails { get; set; }

Whether to include exception details in responses (should only be true in Development)

string TypeUrlBase { get; set; }

Base URL for problem detail types (e.g., “https://api.nuvora.nexus/problems”)

IExceptionMapper

public interface IExceptionMapper

Maps exceptions to HTTP status codes and problem detail types

Methods

(int StatusCode, string Type, string Title) Map(Exception exception)

Maps an exception to HTTP status code, problem type, and title

bool IsSafeToExposeMessage(Exception exception)

Whether Exception.Message is safe to expose to clients in a ProblemDetails response when ExceptionHandlingOptions.IncludeExceptionDetails is disabled. Only known-safe exception families (those whose messages are written for clients, e.g. the RelayException hierarchy) should return true; arbitrary exceptions (ArgumentException etc.) may leak internals and get a generic detail instead. The default implementation keeps custom mappers source-compatible.

Nuvora.Nexus.Relay.Web.Exceptions

BusinessRuleException

public class BusinessRuleException : RelayException

Exception thrown when a business rule is violated Maps to HTTP 422 Unprocessable Entity

Constructors

BusinessRuleException()
BusinessRuleException(string message)
BusinessRuleException(string message, Dictionary<string, object>? context)
BusinessRuleException(string message, Exception innerException)
BusinessRuleException(string message, Exception innerException, Dictionary<string, object>? context)

ConflictException

public class ConflictException : RelayException

Exception thrown when a resource conflict occurs (e.g., duplicate key, optimistic concurrency) Maps to HTTP 409 Conflict

Constructors

ConflictException()
ConflictException(string message)
ConflictException(string message, Dictionary<string, object>? context)
ConflictException(string message, Exception innerException)
ConflictException(string message, Exception innerException, Dictionary<string, object>? context)

ExternalServiceException

public class ExternalServiceException : RelayException

Exception thrown when an external service call fails Maps to HTTP 503 Service Unavailable

Constructors

ExternalServiceException()
ExternalServiceException(string message)
ExternalServiceException(string message, Dictionary<string, object>? context)
ExternalServiceException(string message, Exception innerException)
ExternalServiceException(string message, Exception innerException, Dictionary<string, object>? context)

ForbiddenException

public class ForbiddenException : RelayException

Exception thrown when a user is authenticated but lacks the required permissions. Maps to HTTP 403 Forbidden.

This type intentionally duplicates Nuvora.Nexus.Relay.Auth.Exceptions.ForbiddenException: the Web package cannot depend on the Auth package (that would drag in the Relay/Core dependency graph), so each package ships its own type and DefaultExceptionMapper matches the Auth variant by full type name instead of by reference.

Constructors

ForbiddenException()
ForbiddenException(string message)
ForbiddenException(string message, Dictionary<string, object>? context)
ForbiddenException(string message, Exception innerException)
ForbiddenException(string message, Exception innerException, Dictionary<string, object>? context)

NotFoundException

public class NotFoundException : RelayException

Exception thrown when a requested resource is not found Maps to HTTP 404 Not Found

Constructors

NotFoundException()
NotFoundException(string message)
NotFoundException(string message, Dictionary<string, object>? context)
NotFoundException(string message, Exception innerException)
NotFoundException(string message, Exception innerException, Dictionary<string, object>? context)

RelayException

public class RelayException : Exception

Base exception class for all Relay framework exceptions

Constructors

RelayException()
RelayException(string message)
RelayException(string message, Dictionary<string, object>? context)
RelayException(string message, Exception innerException)
RelayException(string message, Exception innerException, Dictionary<string, object>? context)

Properties

Dictionary<string, object>? Context { get; }

Additional context data associated with the exception

UnauthorizedException

public class UnauthorizedException : RelayException

Exception thrown when a user is not authenticated but authentication is required. Maps to HTTP 401 Unauthorized.

This type intentionally duplicates Nuvora.Nexus.Relay.Auth.Exceptions.UnauthorizedException: the Web package cannot depend on the Auth package (that would drag in the Relay/Core dependency graph), so each package ships its own type and DefaultExceptionMapper matches the Auth variant by full type name instead of by reference.

Constructors

UnauthorizedException()
UnauthorizedException(string message)
UnauthorizedException(string message, Dictionary<string, object>? context)
UnauthorizedException(string message, Exception innerException)
UnauthorizedException(string message, Exception innerException, Dictionary<string, object>? context)

ValidationException

public class ValidationException : RelayException

Exception thrown when validation fails Maps to HTTP 400 Bad Request

Constructors

ValidationException()
ValidationException(string message)
ValidationException(string message, Dictionary<string, string[]> errors)
ValidationException(string message, Dictionary<string, string[]> errors, Dictionary<string, object>? context)
ValidationException(string message, Exception innerException)

Properties

Dictionary<string, string[]>? Errors { get; }

Dictionary of validation errors, keyed by field name

Nuvora.Nexus.Relay.Web.Middleware

CorrelationIdMiddleware

public class CorrelationIdMiddleware

Middleware that generates and propagates correlation IDs for request tracing

Constructors

CorrelationIdMiddleware(RequestDelegate next, ILogger<CorrelationIdMiddleware> logger)

Methods

Task InvokeAsync(HttpContext context)

GlobalExceptionHandlerMiddleware

public class GlobalExceptionHandlerMiddleware

Global exception handler middleware that catches all unhandled exceptions and returns Problem Details (RFC 7807) formatted responses

Constructors

GlobalExceptionHandlerMiddleware(RequestDelegate next, ILogger<GlobalExceptionHandlerMiddleware> logger, IExceptionMapper exceptionMapper, ExceptionHandlingOptions options)

Methods

Task InvokeAsync(HttpContext context)

Nuvora.Nexus.Relay.Web.Models

Cursor

public class Cursor

Represents a cursor for cursor-based pagination

Properties

Dictionary<string, object> Values { get; set; }

The sort key values used for pagination (e.g., CreatedAt, Id)

Methods

T? GetValue<T>(string key)

Gets a value from the cursor

static Cursor? Decode(string? encodedCursor)

Decodes a base64 string to a Cursor object. Returns null for malformed cursors (invalid base64 or invalid/too-deep JSON); only those expected failures are caught so genuine runtime faults (e.g. OutOfMemoryException) still propagate.

string Encode()

Encodes the cursor to a base64 string

void SetValue<T>(string key, T value)

Sets a value in the cursor

CursorBasedPagination

public class CursorBasedPagination : PaginationParameters

Cursor-based pagination parameters

Properties

int Limit { get; set; }

Number of items to return. Defaults to 10, maximum 100.

string? Cursor { get; set; }

Cursor for the current position. If null, starts from the beginning.

Methods

override void Normalize()

Normalizes pagination parameters

CursorBasedResult<T>

public class CursorBasedResult<T>

Result for cursor-based pagination

Properties

IEnumerable<T> Items { get; set; }

The items in the current page

string? NextCursor { get; set; }

The cursor for the next page (null if there are no more pages)

Methods

Pagination ToPagination(string? currentCursor, int pageSize)

Creates a Pagination object from this cursor-based result

OffsetBasedPagination

public class OffsetBasedPagination : PaginationParameters

Offset-based pagination parameters (offset + limit)

Properties

int Limit { get; set; }

Maximum number of items to return. Defaults to 10, maximum 100.

int Offset { get; set; }

Number of items to skip (0-based). Defaults to 0.

Methods

int GetPage()

Calculates the page number from offset and limit. Computed in long arithmetic and clamped to Int32.MaxValue so large offsets (e.g. Offset=int.MaxValue, Limit=1) do not overflow to a negative page number.

int GetPageSize()

Gets the page size (same as limit)

override void Normalize()

Normalizes pagination parameters

PageBasedPagination

public class PageBasedPagination : PaginationParameters

Page-based pagination parameters (page number + page size)

Properties

int Page { get; set; }

Page number (1-based). Defaults to 1.

int PageSize { get; set; }

Number of items per page. Defaults to 10, maximum 100.

Methods

int GetOffset()

Calculates the offset from page and page size

override void Normalize()

Normalizes pagination parameters

PagedResult<T>

public class PagedResult<T>

Represents a paginated result with metadata

Properties

IEnumerable<T> Items { get; set; }

The items in the current page

Pagination Pagination { get; set; }

Pagination metadata

Pagination

public class Pagination

Represents pagination metadata for a paged result

Properties

bool HasNextPage { get; }

Whether there is a next page

bool HasPreviousPage { get; }

Whether there is a previous page

int Offset { get; set; }

Offset used for pagination (0-based)

int Page { get; set; }

Current page number (1-based)

int PageSize { get; set; }

Number of items per page

int TotalCount { get; set; }

Total number of items across all pages

int TotalPages { get; }

Total number of pages. Returns 0 when Pagination.PageSize is not positive (instead of dividing by zero) or when Pagination.TotalCount is not positive.

string? Cursor { get; set; }

Cursor for cursor-based pagination (if applicable)

string? NextCursor { get; set; }

Next cursor for cursor-based pagination (if applicable)

PaginationParameters

public abstract class PaginationParameters

Base class for pagination parameters

Methods

virtual void Normalize()

Validates and normalizes pagination parameters

Fields

const int DefaultPageSize = 10

Default page size

const int MaxPageSize = 100

Maximum page size allowed

ProblemDetailsResponse

public class ProblemDetailsResponse

Problem Details response following RFC 7807 standard

Properties

DateTime Timestamp { get; set; }

Timestamp when the error occurred

Dictionary<string, string[]>? Errors { get; set; }

Dictionary of validation errors, keyed by field name

int Status { get; set; }

The HTTP status code

string Title { get; set; }

A short, human-readable summary of the problem type

string Type { get; set; }

A URI reference that identifies the problem type

string? Detail { get; set; }

A human-readable explanation specific to this occurrence of the problem

string? Instance { get; set; }

A URI reference that identifies the specific occurrence of the problem

string? TraceId { get; set; }

Correlation ID for tracing the request