Fafp.Templates.WebApi
1.0.2
dotnet new install Fafp.Templates.WebApi@1.0.2
Firefly AI Flow Platform β Web API Template
π¬π§ English | π·πΊ Π ΡΡΡΠΊΠΈΠΉ
Production-ready template for creating ASP.NET Core 10 microservices.
Quick Start
# Install template
dotnet new install Fafp.Templates.WebApi
# Create project
dotnet new faf-webapi -n MyService
# Build and run
cd MyService
dotnet run
Template Parameters
| Parameter | Default | Description |
|---|---|---|
-n, --name |
(folder name) | Project name (replaces WebApiTemplate) |
--Port |
8080 |
HTTP port for the service |
--Author |
Kotrecon |
Author name |
--AuthorEmail |
ermakov_k@mail.ru |
Author email |
--AuthorUrl |
https://github.com/Kotrecon |
Author URL (GitHub profile) |
--Title |
Web API Service |
Service title (used in OpenAPI/Scalar) |
--Version |
1.0.0 |
Service version (semver) |
--Description |
ASP.NET Core Web API microservice |
Service description |
--ServiceHost |
api.example.com |
Service host (used in nginx example) |
-I, --IncludeTests |
true |
Include test project |
Example with all parameters:
dotnet new faf-webapi -n OrderService \
--Port 8082 \
--Author "John Doe" \
--AuthorEmail "john@example.com" \
--Title "Order Service API" \
--Version "1.0.0" \
--Description "Service for processing orders" \
--ServiceHost "orders.mycompany.com"
What's Included
| Component | Description |
|---|---|
| Clean Architecture | Controllers β Services β Repositories |
| Result Pattern | Type-safe error handling via Fafp.ResultPattern |
| Serilog | Structured logging (JSON in prod, human-readable in dev) |
| OpenTelemetry | Tracing, metrics, logs β OTLP endpoint |
| JWT Authentication | Bearer tokens, policy-based authorization |
| Health Checks | Liveness + Readiness on separate port (8081) |
| CORS | Configurable policy |
| Rate Limiting | Request limiting for health endpoints |
| Correlation ID | End-to-end X-Correlation-Id (Guid v7) |
| OpenAPI + Scalar | Scalar UI with JWT authorization |
| API Versioning | URL-based versioning (/api/v1/...) |
| Response Caching | HTTP caching for public endpoints |
| 202 tests | Unit + Integration via TUnit + WebApplicationFactory |
Project Structure
webapi/
βββ .git/
βββ .gitignore
βββ .template.config/
β βββ template.json
βββ docs/
β βββ architecture/
β β βββ adr.md
β β βββ adr.ru.md
β β βββ api.md
β β βββ api.ru.md
β β βββ architecture.md
β β βββ architecture.ru.md
β β βββ auth-flow.md
β β βββ auth-flow.ru.md
β β βββ deployment.md
β β βββ deployment.ru.md
β β βββ observability.md
β β βββ observability.ru.md
β β βββ operability.md
β β βββ operability.ru.md
β βββ configuration.md
β βββ configuration.ru.md
β βββ index.md
β βββ index.ru.md
β βββ quickstart.md
β βββ quickstart.ru.md
β βββ roadmap.md
β βββ roadmap.ru.md
β βββ testing.md
β βββ testing.ru.md
βββ Faf.Templates.WebApi.csproj
βββ global.json
βββ icon.png
βββ LICENSE
βββ README.md
βββ README.ru.md
βββ WebApiTemplate.slnx
β
βββ WebApiTemplate/
β βββ Configuration/Options/
β β βββ ApiMetadataOptions.cs
β β βββ AppSettings.cs
β β βββ ContactInfo.cs
β β βββ JwtOptions.cs
β β βββ OpenTelemetryOptions.cs
β βββ Contracts/Dto/Request/Logging/
β β βββ SetLogLevelRequest.cs
β β βββ SetLogLevelValidator.cs
β βββ Controllers/
β β βββ LoggingController.cs
β βββ Extensions/
β β βββ ConfigurationExtensions.cs
β β βββ ObservabilityExtensions.cs
β β βββ CorrelationId/
β β β βββ CorrelationIdExtensions.cs
β β β βββ CorrelationIdMiddleware.cs
β β βββ Cors/
β β β βββ CorsExtensions.cs
β β βββ ExceptionHandler/
β β β βββ ExceptionHandlerExtensions.cs
β β β βββ ExceptionHandlerMiddleware.cs
β β βββ HealthChecks/
β β β βββ HealthCheckExtensions.cs
β β βββ RateLimiting/
β β β βββ RateLimitingExtensions.cs
β β βββ RequestResponseLogging/
β β βββ RequestResponseLoggingExtensions.cs
β β βββ RequestResponseLoggingMiddleware.cs
β βββ HealthChecks/
β β βββ DatabaseHealthChecker.cs
β β βββ IDatabaseHealthChecker.cs
β β βββ MinimalResponseWriter.cs
β β βββ ReadinessHealthCheck.cs
β βββ Security/
β β βββ AuthenticationExtensions.cs
β β βββ AuthorizationExtensions.cs
β βββ Program.cs
β βββ WebApiTemplate.csproj
β βββ appsettings.json
β βββ appsettings.Development.json
β βββ appsettings.Production.json
β
βββ WebApiTemplate.Tests/
βββ Configuration/Options/
β βββ ApiMetadataOptionsTests.cs
β βββ AppSettingsTests.cs
β βββ ContactInfoTests.cs
β βββ JwtOptionsTests.cs
β βββ OpenTelemetryOptionsTests.cs
βββ Contracts/Dto/
β βββ SetLogLevelRequestTests.cs
βββ Controllers/
β βββ ApiVersioningTests.cs
β βββ LoggingControllerTests.cs
βββ Extensions/
β βββ ConfigurationExtensionsTests.cs
β βββ ObservabilityExtensionsTests.cs
β βββ CorrelationId/
β β βββ CorrelationIdMiddlewareTests.cs
β βββ Cors/
β β βββ CorsExtensionsTests.cs
β βββ ExceptionHandler/
β β βββ ExceptionHandlerMiddlewareTests.cs
β βββ RequestResponseLogging/
β βββ RequestResponseLoggingMiddlewareTests.cs
βββ HealthChecks/
β βββ MinimalResponseWriterTests.cs
β βββ ReadinessHealthCheckTests.cs
βββ Helpers/
β βββ RecursiveValidator.cs
βββ Integration/
β βββ Infrastructure/
β β βββ TestWebApplicationFactory.cs
β βββ AuthenticationTests.cs
β βββ AuthorizationTests.cs
β βββ CorrelationIdE2ETests.cs
β βββ DevTokenEndpointTests.cs
β βββ MetadataEndpointTests.cs
βββ Security/
β βββ AuthenticationExtensionsTests.cs
β βββ AuthorizationExtensionsTests.cs
βββ WebApiTemplate.Tests.csproj
βββ coverlet.runsettings
Endpoints
API (port 8080)
| Endpoint | Method | Description | Access |
|---|---|---|---|
/api/v1/logging/level |
GET | Get current logging level | AuditViewer |
/api/v1/logging/level |
PUT | Change logging level (runtime) | AdminOnly |
/api/v1/logging/categories |
GET | List categories with overrides | AuditViewer |
/api/metadata |
GET | Service info (cached 1 hour) | Anonymous |
/dev/token |
POST | Generate test JWT (Development only) | Anonymous |
Health Checks (port 8081 β internal only)
| Endpoint | Method | Description | Access |
|---|---|---|---|
/health/live |
GET | Liveness probe | Internal |
/health/ready |
GET | Readiness probe | Internal |
/health |
GET | Aggregated status | Internal |
OpenAPI (Development only)
| URL | Description |
|---|---|
http://localhost:8080/scalar/v1 |
Scalar UI (interactive docs) |
http://localhost:8080/openapi/v1.json |
OpenAPI 3.1 document |
Configuration
appsettings.json
{
"Kestrel": {
"Endpoints": {
"Api": { "Url": "http://0.0.0.0:8080" },
"Health": { "Url": "http://0.0.0.0:8081" }
}
},
"AppSettings": {
"ServiceName": "MyService",
"Port": 8080
},
"Jwt": {
"Key": "YourSuperSecretKeyAtLeast32CharactersLong!",
"Issuer": "MyService",
"Audience": "MyService"
},
"OpenTelemetry": {
"Endpoint": "http://otel-collector:4317",
"Protocol": "Grpc",
"Headers": {},
"UseConsoleExporter": false
},
"ApiMetadata": {
"Title": "SERVICE_TITLE_PLACEHOLDER",
"Version": "SERVICE_VERSION_PLACEHOLDER",
"Description": "SERVICE_DESCRIPTION_PLACEHOLDER",
"Developer": {
"Name": "AUTHOR_PLACEHOLDER",
"Email": "AUTHOR_EMAIL_PLACEHOLDER",
"Url": "AUTHOR_URL_PLACEHOLDER"
}
}
}
Environment Variables
| Variable | Required | Description |
|---|---|---|
ASPNETCORE_ENVIRONMENT |
Yes | Production / Development |
Jwt__Key |
Yes | JWT signing key (min 32 chars) |
OpenTelemetry__Endpoint |
No | OTLP endpoint (default: http://localhost:4317) |
Testing
cd MyService.Tests
dotnet test
Result: 202 tests (unit + integration), coverage via coverlet.
Dependencies
Fafp.ResultPattern1.0.0 β type-safe error handlingSerilog.AspNetCoreβ structured loggingOpenTelemetry.*β tracing and metricsMicrosoft.AspNetCore.Authentication.JwtBearerβ JWTScalar.AspNetCoreβ OpenAPI UITUnitβ testing framework
Roadmap
β v1.0.0 β Base template
- Clean Architecture
- Result Pattern integration
- Serilog + OpenTelemetry
- JWT + Health Checks
- 202 tests (TUnit)
- NuGet template package
π v1.1.0 β Docker & DevOps
-
Dockerfile(multi-stage build) -
docker-compose.yml(service + PostgreSQL + OTel Collector) -
.dockerignore - GitHub Actions CI/CD workflow
Author
Kotrecon
Solution Architect from Saint Petersburg. Specialization: .NET, C#, JS, Python, AI/ML, RAG, Agents, DevOps, GitHub, GitLab, CI/CD, Industrial Automation, Industrial Software, DB, PostgreSQL.
License
MIT
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.