Open links in new tab
  1. A simple ASP.NET Core Web API can be built using the controller-based approach to handle CRUD operations. Below is a minimal example for a Todo API that demonstrates creating a project, defining a model, repository, and controller.

    1. Create the Project Using Visual Studio or .NET CLI:

    dotnet new webapi -n TodoApi
    Copied!

    Ensure Use controllers and Enable OpenAPI support are selected if using the Visual Studio template.

    2. Define the Model (Models/TodoItem.cs)

    namespace TodoApi.Models
    {
    public class TodoItem
    {
    public string Key { get; set; }
    public string Name { get; set; }
    public bool IsComplete { get; set; }
    }
    }
    Copied!

    3. Create a Repository (Models/ITodoRepository.cs and Models/TodoRepository.cs)

    using System.Collections.Generic;

    namespace TodoApi.Models
    {
    public interface ITodoRepository
    {
    void Add(TodoItem item);
    IEnumerable<TodoItem> GetAll();
    TodoItem Find(string key);
    TodoItem Remove(string key);
    void Update(TodoItem item);
    }
    }
    Copied!
    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;

    namespace TodoApi.Models
    {
    public class TodoRepository : ITodoRepository
    {
    private static ConcurrentDictionary<string, TodoItem> _todos = new();

    public TodoRepository()
    {
    Add(new TodoItem { Name = "Item1" });
    }

    public IEnumerable<TodoItem> GetAll() => _todos.Values;

    public void Add(TodoItem item)
    {
    item.Key = Guid.NewGuid().ToString();
    _todos[item.Key] = item;
    }

    public TodoItem Find(string key) => _todos.TryGetValue(key, out var item) ? item : null;

    public TodoItem Remove(string key)
    {
    _todos.TryRemove(key, out var item);
    return item;
    }

    public void Update(TodoItem item) => _todos[item.Key] = item;
    }
    }
    Copied!
  1. Understanding API in .NET Core — A Beginner-Friendly …

    Oct 6, 2025 · Unlock the power of APIs in .NET Core with this beginner-friendly guide! Learn to build a simple web API, understand endpoints, and connect …

  2. ASP.NET Core Fundamentals: Build Web APIs on .NET 8

    Nov 12, 2025 · Learn ASP.NET Core essentials for modern Web APIs on .NET 8—minimal APIs, controllers, DI, auth, EF Core, and deployment. Build a complete Todo API.

  3. How to Build a RESTful Web API in ASP.NET Core (.NET …

    Apr 20, 2025 · In this step-by-step guide, we’ll build a RESTful Web API using ASP.NET Core (.NET 9), covering the basics of routing, controllers, and testing …

  4. ASP.NET Core Web API Fundamentals - Dot Net Tutorials

    Understand the fundamentals of ASP.NET Core Web API with an Example. Learn to build robust applications with this powerful framework.

  5. Free ASP.NET Core Web API Course - .NET 10, 125

    The .NET Web API Zero to Hero course by Mukesh Murugan is a free, 125+ lesson ASP.NET Core Web API course built on .NET 10. It covers REST API …

  6. Create web APIs with ASP.NET Core | Microsoft Learn

    Dec 7, 2025 · ASP.NET Core supports creating web APIs using controllers or using Minimal APIs. Controllers in a web API are classes that derive from …

  7. Azure-Samples/dotnet-core-api - GitHub

    16 rows · ASP.NET Core API sample for Azure App Service This is a sample application that you can use to follow along with the tutorial at Run a RESTful API …

  8. Building Your First Web API with ASP.NET Core MVC …

    In this tutorial, you’ll build a simple web API for managing a list of “to-do” items. You won’t build any UI in this tutorial.

  9. .NET Core Web API Features with Code Examples - C

    Jun 30, 2025 · Learn the key features of .NET Core Web API with real code examples. From routing, dependency injection, and middleware to authentication …

  10. People also ask
    Loading
    Unable to load answer