<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Documentation on Dotnet WebApi Util</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/</link><description>Recent content in Documentation on Dotnet WebApi Util</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://artur-rios.github.io/dotnet-webapi-util/docs/index.xml" rel="self" type="application/rss+xml"/><item><title>Architecture</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/architecture/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://artur-rios.github.io/dotnet-webapi-util/docs/architecture/</guid><description>&lt;p&gt;This page shows how the pieces of &lt;code&gt;ArturRios.Util.WebApi&lt;/code&gt; fit together: the request pipeline, the&#10;security model, the response envelope, and the design principles that hold them together.&lt;/p&gt;&#10;&lt;h2 id="request-pipeline"&gt;Request pipeline&lt;/h2&gt;&#10;&lt;p&gt;The library is a thin layer around the standard ASP.NET Core pipeline. &lt;code&gt;WebApiStartup&lt;/code&gt; builds the&#10;&lt;code&gt;WebApplicationBuilder&lt;/code&gt;/&lt;code&gt;WebApplication&lt;/code&gt; through one standard sequence, whose pipeline half adds the three&#10;built-in middlewares with &lt;code&gt;UseStandardMiddlewares()&lt;/code&gt; — &lt;code&gt;AuthenticationMiddleware&lt;/code&gt; only when&#10;&lt;code&gt;AddTokenAuthentication&lt;/code&gt; was registered, with Swagger and CORS (when enabled) served just before it — then&#10;any extra middlewares from &lt;code&gt;WebApiStartupOptions.Middlewares&lt;/code&gt;,&#10;then the controllers:&lt;/p&gt;</description></item><item><title>Configuration</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/configuration/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://artur-rios.github.io/dotnet-webapi-util/docs/configuration/</guid><description>&lt;p&gt;&lt;code&gt;WebApiStartup&lt;/code&gt; is the abstract base class you derive from to bootstrap an ASP.NET Core host: it runs one&#10;standard, opinionated sequence — configuration loading, controllers, the invalid-model-state envelope,&#10;Swagger, the standard middlewares and controller mapping — and leaves you a single method to implement,&#10;&lt;code&gt;ConfigureServices&lt;/code&gt;, for your own services. The sequence is tuned through &lt;code&gt;WebApiStartupOptions&lt;/code&gt;, and every&#10;step in it is also a public extension method, so the same setup can be composed on a plain&#10;&lt;code&gt;WebApplicationBuilder&lt;/code&gt; without the base class.&lt;/p&gt;</description></item><item><title>Endpoint Toggling</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/endpoint-toggle/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://artur-rios.github.io/dotnet-webapi-util/docs/endpoint-toggle/</guid><description>&lt;p&gt;&lt;code&gt;[EndpointToggle]&lt;/code&gt; is an action filter attribute that turns a single endpoint on or off. When the endpoint&#10;is disabled, the request is short-circuited &lt;strong&gt;before the action runs&lt;/strong&gt; and a response is returned in one of&#10;several shapes. The toggle can be fixed in code or resolved from configuration on every request, so an&#10;endpoint can be disabled without a redeploy.&lt;/p&gt;&#10;&lt;h2 id="the-two-forms"&gt;The two forms&lt;/h2&gt;&#10;&lt;p&gt;The attribute has two constructors — pick one per endpoint:&lt;/p&gt;</description></item><item><title>Security</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/security/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://artur-rios.github.io/dotnet-webapi-util/docs/security/</guid><description>&lt;p&gt;&lt;code&gt;ArturRios.Util.WebApi&lt;/code&gt; ships token authentication and role-based authorization as a small, composable&#10;set of pieces: &lt;code&gt;AuthenticationMiddleware&lt;/code&gt; extracts and validates the token and attaches the user, a pair&#10;of attributes/filters declare access rules, and &lt;code&gt;Credentials&lt;/code&gt;/&lt;code&gt;Authentication&lt;/code&gt; give you the record types&#10;for a login flow.&lt;/p&gt;&#10;&lt;p&gt;Two token schemes are supported side by side — the app&amp;rsquo;s own HMAC JWT and Google ID tokens — and either&#10;can be accepted on a given request. Which scheme(s) are enabled, where the token is read from, and how the&#10;user is resolved are all controlled by one &lt;code&gt;AuthenticationOptions&lt;/code&gt; instance, registered via&#10;&lt;code&gt;AddTokenAuthentication&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Middleware &amp; Diagnostics</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/middleware-and-diagnostics/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://artur-rios.github.io/dotnet-webapi-util/docs/middleware-and-diagnostics/</guid><description>&lt;p&gt;&lt;code&gt;ArturRios.Util.WebApi&lt;/code&gt; ships two request-pipeline middlewares — &lt;code&gt;TraceActivityMiddleware&lt;/code&gt; and&#10;&lt;code&gt;ExceptionMiddleware&lt;/code&gt; — plus &lt;code&gt;TracePropagationHandler&lt;/code&gt;, a &lt;code&gt;DelegatingHandler&lt;/code&gt; that carries the same&#10;trace id onto outgoing &lt;code&gt;HttpClient&lt;/code&gt; calls. (The third pipeline middleware, &lt;code&gt;AuthenticationMiddleware&lt;/code&gt;, is&#10;covered on the &lt;a href="../security/"&gt;Security&lt;/a&gt; page.) &lt;code&gt;WebApiStartup&lt;/code&gt; adds all of them for you through&#10;&lt;code&gt;UseStandardMiddlewares()&lt;/code&gt;, as referenced in &lt;a href="../architecture/"&gt;Architecture&lt;/a&gt; and&#10;&lt;a href="../configuration/"&gt;Configuration&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h2 id="webapimiddleware-and-registration-order"&gt;&lt;code&gt;WebApiMiddleware&lt;/code&gt; and registration order&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;UseStandardMiddlewares()&lt;/code&gt; (&lt;code&gt;ArturRios.Util.WebApi.Configuration&lt;/code&gt;) adds the built-in middlewares in a&#10;fixed order:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UseStandardMiddlewares&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 0. UseForwardedHeaders — no-op until ForwardedHeadersOptions is configured&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 1. TraceActivityMiddleware — assigns/propagates a W3C trace id&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 2. ExceptionMiddleware — turns unhandled exceptions into a JSON error envelope&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 3. Swagger JSON + UI — only when the Swagger generator was registered&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 4. UseCors(policy) — only when a CORS policy name is passed&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 5. AuthenticationMiddleware — only when AddTokenAuthentication was registered&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;TraceActivityMiddleware&lt;/code&gt; runs first so the trace id is available to everything downstream, including&#10;exception logging; &lt;code&gt;ExceptionMiddleware&lt;/code&gt; runs next so it can catch exceptions thrown by authentication or&#10;the endpoint itself; Swagger and CORS come before &lt;code&gt;AuthenticationMiddleware&lt;/code&gt; (see &lt;a href="../security/"&gt;Security&lt;/a&gt;),&#10;which runs last, so the Swagger UI and CORS preflight requests never need a token.&#10;&lt;code&gt;WebApiStartup&lt;/code&gt; calls it as the first step of the pipeline; on a plain &lt;code&gt;WebApplication&lt;/code&gt;, call it yourself.&lt;/p&gt;</description></item><item><title>HTTP Client</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/http-client/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://artur-rios.github.io/dotnet-webapi-util/docs/http-client/</guid><description>&lt;p&gt;&lt;code&gt;ArturRios.Util.WebApi&lt;/code&gt; gives you a thin base for typed clients that call another web API:&#10;&lt;code&gt;BaseWebApiClient&lt;/code&gt; owns a shared &lt;code&gt;HttpGateway&lt;/code&gt;, and &lt;code&gt;BaseWebApiClientRoute&lt;/code&gt; groups related endpoints&#10;under a base URL with helpers for authenticating and carrying the resulting bearer token.&lt;/p&gt;&#10;&lt;h2 id="basewebapiclient"&gt;&lt;code&gt;BaseWebApiClient&lt;/code&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;BaseWebApiClient&lt;/code&gt; is abstract and exposes a protected &lt;code&gt;HttpGateway Gateway&lt;/code&gt; that every route object uses&#10;to issue requests. It has two constructors:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;BaseWebApiClient(HttpClient httpClient)&lt;/code&gt;&lt;/strong&gt; — wraps an existing &lt;code&gt;HttpClient&lt;/code&gt;. &lt;strong&gt;Prefer this one&lt;/strong&gt;: it&#10;lets the client be created through &lt;code&gt;IHttpClientFactory&lt;/code&gt; (via &lt;code&gt;AddHttpClient&amp;lt;T&amp;gt;()&lt;/code&gt;), which manages the&#10;underlying &lt;code&gt;HttpClient&lt;/code&gt;&amp;rsquo;s lifetime and connection pooling for you and is what lets you attach message&#10;handlers like &lt;code&gt;TracePropagationHandler&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;BaseWebApiClient(string baseUrl)&lt;/code&gt;&lt;/strong&gt; — constructs its own &lt;code&gt;HttpClient&lt;/code&gt; with &lt;code&gt;BaseAddress = baseUrl&lt;/code&gt;.&#10;Simpler for quick/manual use, but you lose &lt;code&gt;IHttpClientFactory&lt;/code&gt;&amp;rsquo;s pooling and the ability to attach&#10;handlers through DI.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Both constructors call the abstract &lt;code&gt;SetRoutes()&lt;/code&gt; method before returning, so a derived class implements&#10;it to instantiate its route objects against the shared &lt;code&gt;Gateway&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Responses</title><link>https://artur-rios.github.io/dotnet-webapi-util/docs/responses/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://artur-rios.github.io/dotnet-webapi-util/docs/responses/</guid><description>&lt;p&gt;&lt;code&gt;ToActionResult&lt;/code&gt; is an extension method (in &lt;code&gt;OutputActionResultExtensions&lt;/code&gt;, namespace&#10;&lt;code&gt;ArturRios.Util.WebApi.AspNetCore&lt;/code&gt;) that converts &lt;code&gt;ArturRios.Output&lt;/code&gt; envelopes — &lt;code&gt;DataOutput&amp;lt;T&amp;gt;&lt;/code&gt;,&#10;&lt;code&gt;ProcessOutput&lt;/code&gt;, and &lt;code&gt;PaginatedOutput&amp;lt;T&amp;gt;&lt;/code&gt; — into ASP.NET Core &lt;code&gt;ActionResult&lt;/code&gt;s, so a controller action&#10;never has to hand-pick a status code for the happy and unhappy paths itself.&lt;/p&gt;&#10;&lt;p&gt;&lt;code&gt;ToActionResult&lt;/code&gt; replaces the static &lt;code&gt;ResponseResolver.Resolve(output, ...)&lt;/code&gt;, which was removed in 5.0.0&#10;with no change in behavior: replace each &lt;code&gt;ResponseResolver.Resolve(output, ...)&lt;/code&gt; call with&#10;&lt;code&gt;output.ToActionResult(...)&lt;/code&gt;.&lt;/p&gt;&#10;&lt;h2 id="toactionresult-overloads"&gt;&lt;code&gt;ToActionResult&lt;/code&gt; overloads&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;ToActionResult&lt;/code&gt; has three overloads, one per envelope type:&lt;/p&gt;</description></item></channel></rss>