$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
.NET / C#intermediateNew

ASP.NET Core API

Share

Scaffold ASP.NET Core Web API with controllers and middleware

Works with OpenClaude

You are an ASP.NET Core developer. The user wants to scaffold a new ASP.NET Core Web API project with controllers, middleware, and proper dependency injection setup.

What to check first

  • Run dotnet --version to verify .NET SDK is installed (6.0 or higher recommended)
  • Confirm you have a terminal open in the directory where you want to create the project

Steps

  1. Create a new ASP.NET Core Web API project using dotnet new webapi -n MyApiProject
  2. Navigate into the project directory with cd MyApiProject
  3. Review the generated Program.cs file — this is where middleware and services are configured in .NET 6+
  4. Create a new controller by adding a file Controllers/ItemsController.cs that inherits from ControllerBase
  5. Add the [ApiController] and [Route("api/[controller]")] attributes to your controller class
  6. Implement HTTP action methods using [HttpGet], [HttpPost], [HttpPut], [HttpDelete] attributes
  7. Register any custom services in Program.cs using builder.Services.AddScoped<IMyService, MyService>()
  8. Add middleware in Program.cs before app.Run() using app.UseMiddleware<CustomMiddleware>() or built-ins like app.UseAuthentication()
  9. Run the API with dotnet run and test endpoints using a tool like Postman or curl

Code

// Program.cs - Main application setup with middleware and DI
var builder = WebApplicationBuilder.CreateBuilder(args);

// Add services to the container
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// Register custom services
builder.Services.AddScoped<IItemService, ItemService>();
builder.Services.AddSingleton<ILogger, ConsoleLogger>();

var app = builder.Build();

// Configure the HTTP request pipeline
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.Run();

// ============================================
// Controllers/ItemsController.cs
[ApiController]
[Route("api/[controller]")]
public class ItemsController : ControllerBase
{
    private readonly IItemService _itemService;
    
    public ItemsController(IItemService itemService)
    {
        _itemService = itemService;
    }
    
    [HttpGet("{id}")]
    public async Task<ActionResult<ItemDto>> GetItem(int id)
    {
        var item = await _itemService.GetItemAsync(id);
        if (item == null)
            return NotFound();
        return Ok(item);
    }

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Category.NET / C#
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
dotnetaspnetapi

Install command:

curl -o ~/.claude/skills/dotnet-api.md https://clskills.in/skills/dotnet/dotnet-api.md

Related .NET / C# Skills

Other Claude Code skills in the same category — free to download.

Want a .NET / C# skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.