Build ASP.NET Core Web API Using GitHub Spec Kit and Copilot – Step-by-Step Guide

Build an ASP.NET Core Web API using GitHub Spec Kit and Copilot. Learn specification, planning, task generation, and implementation.

In Part 1 of this series, we installed GitHub Spec Kit on Windows and configured it to work with GitHub Copilot. Now let's use that setup to build a real application: a Product Management ASP.NET Core Web API using a spec-driven development workflow.

Instead of asking an AI coding assistant to generate an entire application from a vague prompt, we'll first describe what the API should do, create a technical plan, break the work into tasks, and then implement and test the result.

What you'll build
  • An ASP.NET Core Web API for managing products
  • Endpoints to create, read, update, and delete products
  • Validation and consistent HTTP responses
  • A Spec Kit specification, plan, and implementation tasks
  • API tests using an HTTP client and automated tests

What Is Spec-Driven Development?

Spec-driven development (SDD) starts with a clear description of the behavior you want. The specification becomes the reference point for planning, coding, and verification. GitHub Spec Kit provides commands and templates that help organize this workflow with an AI coding assistant.

For this tutorial, the workflow is:

Requirements
    |
    v
/speckit.specify
    |
    v
/speckit.plan
    |
    v
/speckit.tasks
    |
    v
/speckit.implement
    |
    v
Build, test, review

The AI assistant can help generate code, but you still need to review the specification, implementation, and test results.

Prerequisites

  • Windows with PowerShell
  • A supported .NET SDK installed
  • Visual Studio Code and GitHub Copilot Chat access
  • Git installed
  • Python 3.12 and uv, if using the installation approach from Part 1
  • GitHub Spec Kit's specify CLI installed

If you haven't configured Spec Kit yet, start with our previous tutorial: How to Install Spec Kit on Windows with GitHub Copilot | specify-cli Setup. Add a link to your published Part 1 article here.

Verify your tools:

dotnet --version
specify version
git --version

Step 1: Create the ASP.NET Core Web API Project

Open PowerShell in your preferred development folder:

mkdir ProductCatalogApi
cd ProductCatalogApi

dotnet new webapi --use-controllers

dotnet build

This creates an ASP.NET Core Web API with controller support. The project name follows the folder name when no explicit name is supplied.

Open the folder in Visual Studio Code:

code .

Step 2: Initialize Git and Spec Kit

Initialize Git if the folder isn't already a repository:

git init

Next, initialize Spec Kit in the existing project directory. Depending on your installed Specify CLI version, the integration option may be named differently. Check the supported flags first:

specify init --help

For CLI versions supporting the --integration option, a typical command is:

specify init --here --integration copilot --script ps

If your CLI lists --ai instead, use the equivalent option shown by its help output. Confirm any overwrite prompts carefully so your existing .NET files are preserved.

Important: Spec Kit CLI flags and generated file locations can change between releases. Always prefer specify init --help and the instructions generated in your repository over copied commands from an older tutorial.

Open GitHub Copilot Chat in VS Code and check that the Spec Kit slash commands are available. You may need to reload the editor after initialization.

Step 3: Define the Project Requirements

Before generating code, decide what the application must do. We'll build a simple product catalog with these fields:

FieldRule
IdUnique product identifier
NameRequired, maximum 100 characters
PriceMust be greater than zero
StockQuantityCannot be negative

Our API should support these operations:

  • Get all products
  • Get one product by ID
  • Create a product
  • Update a product
  • Delete a product

Step 4: Generate a Specification with /speckit.specify

In GitHub Copilot Chat, enter the following prompt:

/speckit.specify Build a Product Management REST API using ASP.NET Core.
Users must be able to list products, retrieve a product by ID,
create a product, update an existing product, and delete a product.
Each product has an ID, name, price, and stock quantity.
Name is required and limited to 100 characters; price must be
positive; stock quantity cannot be negative.
Return appropriate HTTP status codes for successful operations,
invalid requests, and missing products. Include acceptance
criteria for each operation and automated API tests.

Spec Kit should help create a feature specification. Review it for missing requirements before proceeding. The exact file path depends on the Spec Kit version and initialized templates.

What to check: Are validation rules explicit? Does each endpoint have a clear success response? Are not-found cases documented? Are acceptance criteria testable?

Step 5: Create the Technical Plan with /speckit.plan

Next, tell Copilot how you want the application implemented:

/speckit.plan Use ASP.NET Core Web API with C# and controllers.
Use Entity Framework Core with SQLite for local persistence.
Use dependency injection and asynchronous database operations.
Separate API request models from database entities.
Add automated tests for CRUD operations and validation.
Do not add authentication in this introductory example.
Keep the architecture simple and easy to understand.

The plan should describe the project structure, dependencies, persistence strategy, and testing approach. Check that the plan matches the specification instead of accepting every generated decision automatically.

Why SQLite? It provides a lightweight local database without requiring a SQL Server installation. You can later migrate the application to SQL Server or Azure SQL.

Step 6: Generate Implementation Tasks with /speckit.tasks

Run:

/speckit.tasks

The generated tasks should cover the work in a practical order. For example:

  1. Add Entity Framework Core and SQLite packages.
  2. Create the product entity and database context.
  3. Configure the database connection.
  4. Create request/response models and validation.
  5. Implement CRUD endpoints.
  6. Add database migrations.
  7. Write automated tests.
  8. Build and verify the API.

These are illustrative tasks; the actual list generated by Spec Kit will depend on your specification and plan.

Step 7: Implement the Feature with /speckit.implement

Once the plan and tasks look correct, run:

/speckit.implement

Copilot can now work through the task list and generate application code. Review each significant change, particularly dependency versions, database migrations, validation behavior, and tests.

To understand what the implementation might look like, here are representative pieces of a controller-based ASP.NET Core application. These are examples of expected C# structure, not guaranteed output from Spec Kit.

Product Entity

namespace ProductCatalogApi.Models;

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
    public int StockQuantity { get; set; }
}

Request Model with Validation

using System.ComponentModel.DataAnnotations;

namespace ProductCatalogApi.Models;

public class ProductRequest
{
    [Required]
    [StringLength(100)]
    public string Name { get; set; } = string.Empty;

    [Range(typeof(decimal), "0.01", "79228162514264337593543950335")]
    public decimal Price { get; set; }

    [Range(0, int.MaxValue)]
    public int StockQuantity { get; set; }
}

Entity Framework Core Database Context

using Microsoft.EntityFrameworkCore;
using ProductCatalogApi.Models;

namespace ProductCatalogApi.Data;

public class ProductDbContext : DbContext
{
    public ProductDbContext(DbContextOptions<ProductDbContext> options)
        : base(options) { }

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

Register the Database Context

Install the packages compatible with your project's target .NET version:

dotnet add package Microsoft.EntityFrameworkCore.Sqlite
 dotnet add package Microsoft.EntityFrameworkCore.Design

In Program.cs, add the context registration before builder.Build():

using Microsoft.EntityFrameworkCore;
using ProductCatalogApi.Data;

builder.Services.AddDbContext<ProductDbContext>(options =>
    options.UseSqlite("Data Source=products.db"));

Keep the template's controller registration and mapping in place. If Copilot generated a different configuration, follow the generated project structure and verify that it compiles.

Step 8: Create and Apply the Database Migration

If the implementation uses EF Core migrations, install or update the EF command-line tool to a compatible version:

dotnet tool install --global dotnet-ef

If it is already installed, use dotnet tool update --global dotnet-ef instead. Then run:

dotnet ef migrations add InitialCreate
 dotnet ef database update

This creates the SQLite database schema based on the generated entity model. If your implementation uses a different persistence approach, follow its corresponding setup steps.

Step 9: Run and Test the Web API

Build and start the application:

dotnet build
 dotnet run

Use the actual local URL printed by dotnet run. The following examples assume the generated controller route is /api/products and the app is running at https://localhost:7001. Adjust both values to match your application.

Create a Product

POST https://localhost:7001/api/products
Content-Type: application/json

{
  "name": "Wireless Mouse",
  "price": 799.00,
  "stockQuantity": 25
}

A successful create operation should normally return 201 Created, ideally with a location pointing to the new resource.

Get All Products

GET https://localhost:7001/api/products

Get a Product by ID

GET https://localhost:7001/api/products/1

Update a Product

PUT https://localhost:7001/api/products/1
Content-Type: application/json

{
  "name": "Wireless Mouse Pro",
  "price": 999.00,
  "stockQuantity": 20
}

Delete a Product

DELETE https://localhost:7001/api/products/1

Confirm that the actual generated API implements the requested routes and HTTP responses. Do not assume the endpoints work simply because code was generated.

Step 10: Verify Acceptance Criteria and Tests

Run the generated automated test project, if one was created:

dotnet test

Also manually check these scenarios:

  • Create a valid product and verify it can be retrieved.
  • Submit an empty name and expect a validation error.
  • Submit a zero or negative price and expect a validation error.
  • Submit a negative stock quantity and expect a validation error.
  • Request an unknown product ID and expect 404 Not Found.
  • Update and delete an existing product, then verify the result.

When a test fails, fix the implementation or clarify the specification. Do not remove useful validation or weaken assertions just to make tests pass.

Common Spec Kit and .NET Problems

specify Is Not Recognized

Confirm the CLI is installed and its executable directory is on your PATH. Restart PowerShell after installing a new tool and retry specify version.

Spec Kit Commands Do Not Appear in Copilot Chat

Confirm the project was initialized for GitHub Copilot, open the correct repository folder, and reload VS Code. Check the generated agent instructions and the CLI version.

CLI Option Is Not Recognized

Run specify init --help. Some releases use different option names for selecting an AI integration. Use the flags supported by your installed version.

EF Core Package or Migration Errors

Check that Entity Framework Core packages and dotnet-ef are compatible with the project's target framework. Ensure the application builds before running migrations.

Generated Code Does Not Compile

Read the first build error, check namespaces and dependency registrations, and ask Copilot to fix that specific issue. Rebuild and rerun tests after each change.

Endpoints Return 404

Verify controller routing, app.MapControllers(), the actual port, and the generated route attributes. The example URLs above may differ from the generated implementation.

Best Practices for Using Spec Kit with GitHub Copilot

  • Start with behavior: Explain what users need before deciding how to code it.
  • Keep scope small: A CRUD API is a better first project than an entire enterprise system.
  • Review every artifact: Check specifications, plans, tasks, code, and tests.
  • Define failure cases: Include invalid input and missing resources in the specification.
  • Protect secrets: Never paste API keys, passwords, or production connection strings into prompts.
  • Commit incrementally: Use Git to review changes and recover from incorrect generations.
  • Verify with tests: AI-generated code is a starting point, not proof of correctness.

Frequently Asked Questions

Can I use Spec Kit with an existing ASP.NET Core project?

Yes. Initialize it in the existing repository using the options supported by your CLI version. Review any prompts before overwriting files.

Does Spec Kit automatically write correct code?

No. It structures the development workflow, but generated plans and code still require review, testing, and security checks.

Can I use SQL Server instead of SQLite?

Yes. Specify SQL Server in the technical plan and configure the appropriate Entity Framework Core provider and connection string.

Is GitHub Copilot required?

No. Spec Kit supports different AI coding integrations depending on the version and templates. This tutorial uses GitHub Copilot because it follows our Windows installation guide.

What should I build after this CRUD API?

Good next steps include JWT authentication, pagination, filtering, logging, integration tests, and deployment to Azure App Service.

Conclusion

In this tutorial, we used GitHub Spec Kit and GitHub Copilot to organize the development of an ASP.NET Core Product Management API. We started with requirements, generated a specification, created a technical plan, broke the work into tasks, and then moved on to implementation and testing.

The key idea is simple: describe the expected behavior before generating code. This makes it easier to review what the AI assistant produces and to catch gaps before they reach production.

For the complete setup process, read Part 1: How to Install Spec Kit on Windows with GitHub Copilot | specify-cli Setup and link it to this article before publishing.

Hello! My name is Aniket Shahane and I am a senior software consultant. I hold a post-graduate degree (MTech) in Computer Science and Engineering, and I have a passion for using my technical expertise to solve complex problems. I am excited to be here and eager to share my knowledge and experience with you.

Post a Comment