ASP.NET Core 10.0’s New Web API Development Methods

ASP.NET Core 10.0 provides two options for Web API development: the traditional Controller-based approach and Minimal API. According to the Microsoft Learn documentation, the Controller-based approach uses classes derived from ControllerBase and has a mechanism where controllers are activated and disposed of for each request.

On the other hand, Minimal API aims to create HTTP APIs with minimal dependencies and is suitable for microservices or applications with minimal files, functions, and dependencies.

(Source: Create web APIs with ASP.NET Core)

Controller-based API Implementation Patterns

The Controller-based approach implements standard CRUD operations using the following API endpoints:

  • GET /api/todoitems - Get all To-do items
  • GET /api/todoitems/{id} - Get a specific item by ID
  • POST /api/todoitems - Add a new item
  • PUT /api/todoitems/{id} - Update an existing item
  • DELETE /api/todoitems/{id} - Delete an item

In architectural design, client requests are sent to the controller, and read and write operations are performed between the controller and the data access layer. The model is serialized and returned to the client as a response.

(Source: Tutorial: Create a controller-based web API with ASP.NET Core)

Minimal API’s Lightweight Implementation

Minimal API allows for more concise implementation of APIs. In addition to basic API endpoints, it also provides extended endpoints such as:

  • GET /todoitems/complete - Get completed To-do items
  • PATCH /todoitems/{id} - Partially update an item

For example, APIs can be defined with concise code like this:

var app = WebApplication.Create();
app.MapGet("/people", () => new[]
{
    new Person("Ana"), new Person("Filipe"), new Person("Emillia")
});
app.Run();
record Person(string Name);

This implementation allows you to get a JSON response like [{"name":"Ana"},{"name":"Felipe"},{"name":"Emillia"}] using the curl command.

(Source: Tutorial: Create a Minimal API with ASP.NET Core)

Changes in OpenAPI Integration

From ASP.NET Core 9.0 onwards, OpenAPI support is built-in, replacing Swashbuckle as the default. Swashbuckle is no longer included in project templates, but it can be added manually as a community package.

In traditional Swagger/OpenAPI implementations, the openapi.json specification describes the API’s functionality and drives tools like Swagger UI. The new built-in OpenAPI support allows using Swagger UI for interactive exploration and ad-hoc testing locally.

For projects using Swashbuckle or NSwag in ASP.NET Core 8.0 or earlier, the traditional implementation is still available.

(Source: ASP.NET Core web API documentation with Swagger / OpenAPI)

Summary

  • ASP.NET Core 10.0’s Controller-based approach can be used to implement standard CRUD operation APIs using ControllerBase derived classes.
  • The Minimal API pattern allows for building lightweight HTTP APIs for microservices using WebApplication.Create() and MapGet methods.
  • Built-in OpenAPI support enables API specification generation and Swagger UI integration without relying on Swashbuckle.
  • The Entity Framework Core InMemory provider can be added using the Microsoft.EntityFrameworkCore.InMemory NuGet package, allowing database operations to be executed in memory.