SAIF.Web.API overview¶
Documentation context: Packaged Component (NuGet)
SAIF.Web.API is a cross-cutting infrastructure library for ASP.NET Web API 2 (System.Web.Http) host applications. It supplies a response/error post-processing message handler, a delegated role-based authorization attribute, an HTTPS-enforcement action filter, a static exception-to-HTTP-status mapper, and a request-header extension helper. It contains no controllers, no entry point, and no database access; every authorization decision and configuration value is ultimately assumed to be supplied by the hosting application or by the SAIF.Framework.Core package — no such supply or registration is observed inside this library.*
Purpose¶
- Provide reusable, pluggable ASP.NET Web API 2 pipeline components — a message handler, an authorization attribute, an action filter, and static helpers — that a hosting Web API application registers to obtain consistent response shaping, correlation-ID issuance, observability, transport security, and role-based authorization; no such registration exists in this repository.*
- Consumed by ASP.NET Web API 2 host applications (
net462) that registerApiResponseHandlerinHttpConfiguration.MessageHandlersand decorate their own controllers/actions with[SaifAuthorize]and/or[RequireSSL]; no registration call site exists in this repository, so this describes the intended host-side usage pattern rather than an observed registration.*
Responsibilities¶
- Post-process every outbound Web API response to add a correlation
MessageID/MessageIDUrl, redact sensitive request content from debug traces, and rewrite non-success responses into a structuredErrorResponsebody (ApiResponseHandler). - Enforce role/resource-based authorization on Web API controllers/actions by delegating the authorization decision to an injected
ISecurityApiClient(SaifAuthorizeAttribute). - Enforce HTTPS on Web API actions, with a configurable relaxation for local/developer requests (
RequireSSLAttribute). - Provide a static, reusable mapping from typed
SAIF.API.Exceptions.*exceptions toHttpStatusCodevalues for consuming controllers/exception filters (ExceptionHandler). - Provide a generic, never-throwing request-header reader for consumers (
HttpRequestExtensions).
Key components¶
ApiResponseHandler:DelegatingHandlerthat times each request, resolvesILogService/IEnvironmentServiceper request, normalizes error responses, adds aServer-Nameheader unconditionally, and traces/logs each request whenILogServiceis resolved (no trace/log otherwise).SaifAuthorizeAttribute: sealedAuthorizeAttributeoverride that resolvesISecurityApiClient/IEnvironmentServiceper request and authorizes on OR semantics across caller-supplied role names.RequireSSLAttribute:ActionFilterAttributethat redirects non-HTTPS requests to HTTPS, with a local-request exemption controlled by the ambient application'sRequireSSLForLocalapp setting; no such application or setting exists in this repository.*ExceptionHandler: static utility mappingSAIF.API.Exceptions.*types toHttpStatusCodevalues via catch-clause type dispatch.HttpRequestExtensions: static extension method (TryGetFirstHeader) for reading a request header value without throwing.
Related documentation¶
- Index
- Architecture
- Dependencies
- Configuration
- Operations and processes
- Business rules
- Security and authorization
- API reference
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
src/SAIF.Web.API/SAIF.Web.API.csprojsrc/SAIF.Web.API/ApiResponseHandler.cssrc/SAIF.Web.API/ExceptionHandler.cssrc/SAIF.Web.API/HttpRequestExtensions.cssrc/SAIF.Web.API/RequireSSLAttribute.cssrc/SAIF.Web.API/SaifAuthorizeAttribute.cs