Anarchy.Toolkit.Web
Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Web · Package catalog
Shared ASP.NET Core REST API pipeline and presentation helpers.
dotnet add package Anarchy.Toolkit.Web
- Build an API using
RestApiWebAppStartupBaseand the web entry-point bases for native hosting or AWS Lambda. - Compose the supplied middleware, authentication, Swagger, JSON converters and validation attributes around your application’s endpoints.
- A health controller exposes the shared health-report model. Application-specific scopes and endpoints remain in the consumer.
When to use it
Use this package to host a toolkit-based REST API on ASP.NET Core or AWS Lambda while sharing startup, authentication, health and error-handling conventions. It supplies infrastructure around your endpoints; it does not define your application’s API contracts or business logic.
How to use it
- Define application settings and a settings module, then derive a startup from
RestApiWebAppStartupBase<TAppSettingsDiModule, TAppSettings>. Register your services and configure authorization scopes in its service-configuration hook. - Implement controllers with explicit request/response types and call application services rather than database repositories directly. Keep transport DTOs separate from domain entities.
- Supply the
IReadOnlyCollection<IHealthCheck>consumed by the health controller, using an empty collection if there are no checks or registering the relevant provider reports. - Use
WebAppEntryPoint.RunWebHost<Startup>(args)for a native host and anAwsWebAppEntryPointBaseimplementation for Lambda. Configure real authentication, secrets and environment-specific settings before deployment.
The sample API startup, native entry point and Lambda entry point show the complete structure. Test the HTTP pipeline with Testing.Web.
See the endpoint guide, API sample and toolkit overview.
Swagger UI theme
Swagger UI is themed by default, with the Anarchy palette, header logo (dark text in light mode, white text in dark mode) and favicon, in light and dark mode. Swagger UI starts in dark mode when the system prefers it; the choice made with its header toggle is remembered in the browser. The theme is a mechanism rather than a brand: the stylesheet reads every colour, font and radius from a separate colours stylesheet, so you can rebrand by changing only the colours.
- Change the colours. Copy
wwwroot/css/swagger-colors.cssto your API project’swwwroot/css/swagger-colors.cssand edit the values. Each colour is alight-dark(<light>, <dark>)pair. The packaged assets follow the usualwwwrootlayout (css/swagger-colors.css,css/swagger-theme.css,js/swagger-theme.js,images/logo.png,images/logo-dark.png, andfavicon.svgandfavicon.pngat the root), and files in your API project’swwwrootare served first, so awwwroot/favicon.svgorwwwroot/images/logo.pngreplaces the packaged one the same way. - Point elsewhere.
services.Configure<SwaggerThemeOptions>(...)setsColorsStylesheet,Stylesheet,Script,Logo,DarkLogo,FaviconandFallbackFavicon(relative to the application base path, or absolute). SetStylesheetto your own file to replace the theme entirely. - Turn it off.
services.Configure<SwaggerThemeOptions>(theme => theme.Enabled = false)keeps Swagger UI’s own look and favicon.
The theme uses system fonts only and changes colours, type and borders, not layouts. Swagger UI’s class names are not a stable API, so check the theme after upgrading Swashbuckle.
The OpenAPI document is served as OpenAPI 3.2 by default; set SwaggerOptions.OpenApiVersion with services.Configure<SwaggerOptions>(...) to serve another version.
Releases
See the release notes for the complete release history.