dotnet-webapi

Build ASP.NET Core Web APIs with .NET 10 (C# 14.0). Supports project scaffolding, CRUD operations, Entity Framework integration, dependency injection, testing with xUnit, Docker containerization, and following 2025 best practices. Use when creating REST APIs, microservices, backend services, implementing CRUD operations, setting up Entity Framework, adding authentication/authorization, or containerizing .NET applications. Triggers on .NET, ASP.NET Core, C#, Web API, REST API, microservices, dotnet, csharp development tasks.

16 stars

Best use case

dotnet-webapi is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Build ASP.NET Core Web APIs with .NET 10 (C# 14.0). Supports project scaffolding, CRUD operations, Entity Framework integration, dependency injection, testing with xUnit, Docker containerization, and following 2025 best practices. Use when creating REST APIs, microservices, backend services, implementing CRUD operations, setting up Entity Framework, adding authentication/authorization, or containerizing .NET applications. Triggers on .NET, ASP.NET Core, C#, Web API, REST API, microservices, dotnet, csharp development tasks.

Teams using dotnet-webapi should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/dotnet-webapi/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/dotnet-webapi/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/dotnet-webapi/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How dotnet-webapi Compares

Feature / Agentdotnet-webapiStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Build ASP.NET Core Web APIs with .NET 10 (C# 14.0). Supports project scaffolding, CRUD operations, Entity Framework integration, dependency injection, testing with xUnit, Docker containerization, and following 2025 best practices. Use when creating REST APIs, microservices, backend services, implementing CRUD operations, setting up Entity Framework, adding authentication/authorization, or containerizing .NET applications. Triggers on .NET, ASP.NET Core, C#, Web API, REST API, microservices, dotnet, csharp development tasks.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# .NET 10 Web API Development

Build production-ready ASP.NET Core Web APIs with .NET 10 using best practices from 2025.

## Quick Start

Create a new Web API project:

```bash
scripts/new_api.sh <project_name> [output_directory]
```

**Example:**
```bash
scripts/new_api.sh ProductsApi
cd ProductsApi
dotnet build
dotnet run --project ProductsApi.Api
```

This creates:
- Solution with API and Test projects
- Controller-based Web API (.NET 10)
- xUnit test project with integration testing setup
- Proper folder structure (Controllers, Models, Services)
- .gitignore configured for .NET

---

## Core Features

### 1. Project Scaffolding

**Create New API Project:**
```bash
scripts/new_api.sh MyApi ./projects
```

Generates:
- `MyApi.Api` - Main API project with controllers
- `MyApi.Tests` - xUnit test project with integration testing
- Solution file linking both projects
- Standard folder structure
- Test dependencies (FluentAssertions, WebApplicationFactory)

### 2. Add CRUD Entities

**Generate Entity with Controller and Service:**
```bash
scripts/add_entity.sh <entity_name> <project_path>
```

**Example:**
```bash
scripts/add_entity.sh Product ./MyApi
scripts/add_entity.sh Customer ./MyApi
```

Generates for each entity:
- Model class (`Models/Product.cs`)
- Service interface (`Services/IProductService.cs`)
- Service implementation (`Services/ProductService.cs`)
- CRUD controller (`Controllers/ProductController.cs`)
- Automatic service registration in DI container

**API Endpoints Created:**
```
GET    /api/Product        - Get all
GET    /api/Product/{id}   - Get by ID
POST   /api/Product        - Create
PUT    /api/Product/{id}   - Update
DELETE /api/Product/{id}   - Delete
```

### 3. Package Management

**Add NuGet Packages:**
```bash
scripts/add_package.sh <project_path> <package_name|preset>
```

**Presets:**
```bash
# Entity Framework with PostgreSQL
scripts/add_package.sh ./MyApi ef-postgres

# Entity Framework with SQL Server
scripts/add_package.sh ./MyApi ef-sqlserver

# JWT Authentication
scripts/add_package.sh ./MyApi auth

# FluentValidation
scripts/add_package.sh ./MyApi validation

# Individual package
scripts/add_package.sh ./MyApi Newtonsoft.Json
```

### 4. Docker Support

**Generate Dockerfile and docker-compose:**
```bash
scripts/generate_dockerfile.sh <project_path>
```

**Example:**
```bash
scripts/generate_dockerfile.sh ./MyApi
```

Generates:
- Multi-stage optimized Dockerfile
- docker-compose.yml with PostgreSQL
- .dockerignore
- Non-root user configuration
- Health check setup

**Build and run:**
```bash
docker-compose up -d
docker-compose logs -f api
```

---

## .NET 10 Features

### Built-in Features

**OpenAPI 3.1 Support:**
```csharp
// Program.cs
builder.Services.AddOpenApi();

if (app.Environment.IsDevelopment())
{
    app.MapOpenApi(); // /openapi/v1.json
}
```

**Automatic Minimal API Validation:**
DataAnnotations are automatically validated in .NET 10 for Minimal APIs and controllers.

**Output Caching:**
```csharp
builder.Services.AddOutputCache();
app.UseOutputCache();

[OutputCache(Duration = 300)]
[HttpGet]
public async Task<IActionResult> GetAll()
```

**Rate Limiting:**
```csharp
builder.Services.AddRateLimiter(options =>
{
    options.AddFixedWindowLimiter("api", config =>
    {
        config.PermitLimit = 100;
        config.Window = TimeSpan.FromMinutes(1);
    });
});
```

### C# 14.0 Features

Use latest C# features:
- Primary constructors
- Collection expressions
- Required members
- Init-only properties

---

## Development Workflows

### Typical Development Flow

1. **Create project:**
   ```bash
   scripts/new_api.sh OrderService
   cd OrderService
   ```

2. **Add entities:**
   ```bash
   scripts/add_entity.sh Order .
   scripts/add_entity.sh OrderItem .
   ```

3. **Add database:**
   ```bash
   scripts/add_package.sh . ef-postgres
   ```

4. **Build and run:**
   ```bash
   dotnet build
   dotnet run --project OrderService.Api
   ```

5. **Test:**
   ```bash
   dotnet test
   ```

6. **Dockerize:**
   ```bash
   scripts/generate_dockerfile.sh .
   docker-compose up
   ```

### Entity Framework Integration

After adding EF packages, configure DbContext:

```csharp
// Data/ApplicationDbContext.cs
public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options) { }

    public DbSet<Product> Products => Set<Product>();
}

// Program.cs
builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

// appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=mydb;Username=postgres;Password=postgres"
  }
}
```

**Run migrations:**
```bash
dotnet ef migrations add Initial --project MyApi.Api
dotnet ef database update --project MyApi.Api
```

### Authentication Setup

After adding auth package:

```csharp
// Program.cs
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ValidateIssuerSigningKey = true,
            ValidIssuer = builder.Configuration["Jwt:Issuer"],
            ValidAudience = builder.Configuration["Jwt:Audience"],
            IssuerSigningKey = new SymmetricSecurityKey(
                Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
        };
    });

app.UseAuthentication();
app.UseAuthorization();

// Protect endpoints
[Authorize]
[HttpGet("admin")]
public IActionResult AdminOnly() => Ok("Admin data");
```

---

## Best Practices

### Controller Pattern

Generated controllers follow best practices:

```csharp
[ApiController]
[Route("api/[controller]")]
public class ProductController : ControllerBase
{
    private readonly IProductService _service;
    private readonly ILogger<ProductController> _logger;

    // Constructor injection
    public ProductController(
        IProductService service,
        ILogger<ProductController> logger)
    {
        _service = service;
        _logger = logger;
    }

    // Documented endpoints
    /// <summary>
    /// Get all products
    /// </summary>
    [HttpGet]
    [ProducesResponseType(StatusCodes.Status200OK)]
    public async Task<ActionResult<IEnumerable<Product>>> GetAll()

    // Proper status codes
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status201Created)]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    public async Task<ActionResult<Product>> Create(Product entity)
    {
        var created = await _service.CreateAsync(entity);
        return CreatedAtAction(nameof(GetById), new { id = created.Id }, created);
    }
}
```

### Service Layer Pattern

```csharp
// Interface
public interface IProductService
{
    Task<IEnumerable<Product>> GetAllAsync();
    Task<Product?> GetByIdAsync(int id);
    Task<Product> CreateAsync(Product entity);
    Task<Product?> UpdateAsync(int id, Product entity);
    Task<bool> DeleteAsync(int id);
}

// Implementation with business logic
public class ProductService : IProductService
{
    // In-memory for demo, replace with repository/DbContext
    private readonly List<Product> _entities = new();

    public async Task<Product> CreateAsync(Product entity)
    {
        entity.Id = _nextId++;
        entity.CreatedAt = DateTime.UtcNow;
        _entities.Add(entity);
        return entity;
    }
}
```

---

## Testing

Generated test projects include integration testing setup:

```csharp
public class ProductsEndpointTests : IClassFixture<WebApplicationFactory<Program>>
{
    private readonly HttpClient _client;

    public ProductsEndpointTests(WebApplicationFactory<Program> factory)
    {
        _client = factory.CreateClient();
    }

    [Fact]
    public async Task GetAll_ReturnsSuccessStatusCode()
    {
        var response = await _client.GetAsync("/api/products");
        response.EnsureSuccessStatusCode();
    }
}
```

**Run tests:**
```bash
dotnet test
dotnet test --logger "console;verbosity=detailed"
```

---

## References

For detailed guidance, see:

### API Best Practices
`references/api_best_practices.md` - Comprehensive guide covering:
- RESTful API design
- HTTP status codes
- Error handling patterns
- Validation strategies
- Authentication & authorization
- Dependency injection
- Logging best practices
- Performance optimization
- OpenAPI documentation

### Testing Patterns
`references/testing_patterns.md` - Testing guide including:
- xUnit fundamentals
- Unit testing with Moq
- Integration testing with WebApplicationFactory
- Test data builders
- FluentAssertions usage
- Common testing patterns

### Common Packages
`references/common_packages.md` - NuGet package guide for:
- Database providers (EF Core, Dapper)
- Authentication (JWT, Identity)
- Validation (FluentValidation)
- Testing tools (xUnit, Moq, FluentAssertions)
- Logging (Serilog)
- Utilities (AutoMapper, MediatR, Polly)

---

## Common Scenarios

### Scenario 1: New CRUD API

```bash
# Create project
scripts/new_api.sh InventoryApi

# Add entities
scripts/add_entity.sh Product ./InventoryApi
scripts/add_entity.sh Category ./InventoryApi

# Add database
scripts/add_package.sh ./InventoryApi ef-postgres

# Run
cd InventoryApi
dotnet run --project InventoryApi.Api
```

### Scenario 2: Microservice with Docker

```bash
# Create and setup
scripts/new_api.sh OrderService
scripts/add_entity.sh Order ./OrderService
scripts/add_package.sh ./OrderService ef-postgres
scripts/generate_dockerfile.sh ./OrderService

# Deploy
cd OrderService
docker-compose up -d
```

### Scenario 3: Authenticated API

```bash
scripts/new_api.sh SecureApi
scripts/add_entity.sh User ./SecureApi
scripts/add_package.sh ./SecureApi auth
scripts/add_package.sh ./SecureApi validation
```

---

## Troubleshooting

### .NET SDK Not Found

Ensure .NET 10 SDK is installed:
```bash
dotnet --version  # Should be 10.x
```

Install from: https://dotnet.microsoft.com/download/dotnet/10.0

### Port Already in Use

Change port in Properties/launchSettings.json or use environment variable:
```bash
ASPNETCORE_HTTP_PORTS=5001 dotnet run --project MyApi.Api
```

### Docker Build Fails

Ensure Docker daemon is running:
```bash
docker ps
```

Check Dockerfile paths match project structure.

### EF Migrations Fail

Ensure connection string is correct and database is accessible:
```bash
dotnet ef database update --verbose --project MyApi.Api
```

---

## Integration with Other Skills

Works well with:
- `postgres-query` - Query databases created by your API
- `postgres-backup-restore` - Restore test data for development
- `ruby-rails` - Interop with Rails backends

---

## Summary

This skill provides:

✅ Rapid project scaffolding
✅ CRUD entity generation
✅ NuGet package management
✅ Docker containerization
✅ .NET 10 best practices
✅ Testing setup included
✅ Production-ready code structure
✅ Comprehensive documentation

Start building modern Web APIs with .NET 10 today!

Related Skills

dotnet-windbg-debugging

16
from diegosouzapw/awesome-omni-skill

Debugs Windows apps via WinDbg MCP. Crash, hang, high-CPU, and memory triage from dumps or live attach.

dotnet-to-react-python-refactor

16
from diegosouzapw/awesome-omni-skill

Agent skill for refactoring .NET applications into a React frontend + Python backend. Use for migrating/modernizing .NET apps (ASP.NET MVC, Web API, Blazor, Web Forms) to React + Python, or analyzing .NET codebases for migration planning.

dotnet-testing

16
from diegosouzapw/awesome-omni-skill

Write and run .NET tests following TDD principles. Use when writing tests, implementing TDD workflow, verifying test coverage, or debugging test failures.

dotnet-maui

16
from diegosouzapw/awesome-omni-skill

.NET MAUI component and application patterns Triggers on: **/*.xaml, **/*.cs

dotnet-framework

16
from diegosouzapw/awesome-omni-skill

Guidance for working with .NET Framework projects. Includes project structure, C# language version, NuGet management, and best practices. Triggers on: **/*.csproj, **/*.cs

dotnet-framework-4-8-expert

16
from diegosouzapw/awesome-omni-skill

Expert .NET Framework 4.8 specialist mastering legacy enterprise applications. Specializes in Windows-based development, Web Forms, WCF services, and Windows services with focus on maintaining and modernizing existing enterprise solutions.

dotnet-backend-patterns

16
from diegosouzapw/awesome-omni-skill

Master C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuratio...

dotnet-aspire

16
from diegosouzapw/awesome-omni-skill

Adds .NET Aspire cloud-native orchestration to existing .NET solutions. Analyzes solution structure to identify services (APIs, web apps, workers), creates AppHost and ServiceDefaults projects, configures service discovery, adds NuGet packages, and sets up distributed application orchestration. Use when adding Aspire to .NET solutions or creating new cloud-ready distributed applications.

dotnet-aspire-patterns

16
from diegosouzapw/awesome-omni-skill

Orchestrates .NET Aspire apps. AppHost, service discovery, components, dashboard, health checks.

dotnet-advisor

16
from diegosouzapw/awesome-omni-skill

Routes .NET/C# work to domain skills. Loads coding-standards for code paths.

copilot-sdk-dotnet

16
from diegosouzapw/awesome-omni-skill

Build applications with GitHub Copilot CLI SDKs for .NET. Use for direct CopilotClient integration or Microsoft Agent Framework. Covers sessions, streaming, tools, MCP, permissions, and multi-agent workflows.

azure-eventgrid-dotnet

16
from diegosouzapw/awesome-omni-skill

Azure Event Grid SDK for .NET. Client library for publishing and consuming events with Azure Event Grid. Use for event-driven architectures, pub/sub messaging, CloudEvents, and EventGridEvents.