Architecture
This page shows how the pieces of ArturRios.Util.WebApi fit together: the request pipeline, the security model, the response envelope, and the design…
ArturRios.Util.WebApi is a set of building blocks for ASP.NET Core web APIs in .NET. It bundles a
base class for bootstrapping the host (configuration, Swagger, middleware pipeline), token authentication
that reads the token from the header, a cookie, or either and validates it as the app’s own JWT and/or a
Google ID token (with role-based authorization), cross-cutting middleware for exceptions and distributed
tracing, a thin typed-HttpClient base for calling other services, and a resolver that turns
ArturRios.Output envelopes into ActionResults.
A typical request set up with the built-in middlewares flows through tracing, exception handling and authentication before it reaches your endpoint:
flowchart LR
Client["Client request"] --> Trace["TraceActivityMiddleware<br/><i>assigns/propagates W3C traceparent</i>"]
Trace --> Exception["ExceptionMiddleware<br/><i>catches unhandled exceptions</i>"]
Exception --> Auth["AuthenticationMiddleware<br/><i>validates the request token, attaches IAuthenticatedUser</i>"]
Auth --> Endpoint["Controller / endpoint"]
Endpoint --> Resolver["ToActionResult<br/><i>Output envelope → ActionResult</i>"]
Resolver --> Client| Area | What it does | Docs |
|---|---|---|
| Configuration / bootstrap | WebApiStartup runs one standard sequence — configuration loading, Swagger, the middleware pipeline — leaving you a single ConfigureServices method, and every step is also a standalone extension; WebApiParameters parses command-line startup args. | Configuration |
| Security (JWT, Google + roles) | AuthenticationMiddleware reads the token from the header, a cookie, or either, and validates it as an app HMAC JWT or a Google ID token (either accepted per request), attaching an IAuthenticatedUser; [Authorize], [AllowAnonymous] and [RoleRequirement(...)] declare access rules. | Security |
| Middleware & diagnostics | ExceptionMiddleware converts unhandled exceptions into a JSON error envelope; TraceActivityMiddleware and TracePropagationHandler propagate the W3C traceparent/tracestate across a request and its outgoing calls. | Middleware & Diagnostics |
| HTTP client | BaseWebApiClient / BaseWebApiClientRoute give a typed client a shared HttpGateway, route grouping, and helpers to authenticate and carry the resulting bearer token on subsequent calls. | HTTP Client |
| Responses | output.ToActionResult(...) wraps DataOutput<T>, PaginatedOutput<T> and ProcessOutput in an ActionResult, defaulting to 200/400 based on Success unless a status code is supplied. | Responses |
| Endpoint toggling | [EndpointToggle] enables or disables a single endpoint from a compile-time flag or a runtime appsettings.json/environment-variable value, shaping the disabled response as an empty status code, the action’s default value, a ProcessOutput envelope, or a thrown EndpointDisabledException. | Endpoint Toggling |
Requires .NET 10 or later.
dotnet add package ArturRios.Util.WebApi
Endpoints return an ArturRios.Output envelope — DataOutput<T> (data + success/errors) or, for
operations with no payload, ProcessOutput — and ToActionResult maps that envelope onto an
ActionResult, so success and failure both flow through the same, predictable shape instead of thrown
exceptions.
WebApiStartup and WebApiParameters.BaseWebApiClient.ArturRios.Output envelopes into ActionResults.The source lives at github.com/artur-rios/dotnet-webapi-util, licensed under the MIT License.
This page shows how the pieces of ArturRios.Util.WebApi fit together: the request pipeline, the security model, the response envelope, and the design…
WebApiStartup is the abstract base class you derive from to bootstrap an ASP.NET Core host: it runs one standard, opinionated sequence — configuration loading, controllers, the…
[EndpointToggle] is an action filter attribute that turns a single endpoint on or off. When the endpoint is disabled, the request is short-circuited **before…
ArturRios.Util.WebApi ships token authentication and role-based authorization as a small, composable set of pieces: AuthenticationMiddleware extracts and…
ArturRios.Util.WebApi ships two request-pipeline middlewares — TraceActivityMiddleware and ExceptionMiddleware — plus TracePropagationHandler, a…
ArturRios.Util.WebApi gives you a thin base for typed clients that call another web API: BaseWebApiClient owns a shared HttpGateway, and…
ToActionResult is an extension method that converts ArturRios.Output envelopes — DataOutput<T>, ProcessOutput, and PaginatedOutput<T> — into ASP.NET…