liveBook · Manning

CRUD

As explained in ASP.NET Core in Action, 3e

A CRUD operation is an operation that creates, reads, updates, or deletes persistent data.

CRUD names the four operations used to manage persistent data: create, read, update, and delete. In a minimal API, different HTTP verbs can expose these operations over a collection or database. section 5.2.3 section 12.0

A typical CRUD API assigns one operation to each endpoint action:

Updating an entity with EF Core

A reliable update flow reads the entity by ID, changes its properties, and saves the changes. Keeping this work in a service rather than the API handler separates application transport from business logic. section 12.4.4

Listing 5.2 Creating route handlers for a simple CRUD API
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
WebApplication app = builder.Build();
 
app.MapGet("/fruit", () => Fruit.All);                          #1
 
var getFruit = (string id) => Fruit.All[id];                    #2
app.MapGet("/fruit/{id}", getFruit);                            #2
 
app.MapPost("/fruit/{id}", Handlers.AddFruit);                  #3
 
Handlers handlers = new();                                      #4
app.MapPut("/fruit/{id}", handlers.ReplaceFruit);               #4
 
app.MapDelete("/fruit/{id}", DeleteFruit);                      #5
 
app.Run();
 
void DeleteFruit(string id)                                     #5
{
    Fruit.All.Remove(id);
}
 
record Fruit(string Name, int Stock)
{
    public static readonly Dictionary<string, Fruit> All = new();
};
 
class Handlers
{
    public void ReplaceFruit(string id, Fruit fruit)            #6
    {
        Fruit.All[id] = fruit;
    }
 
    public static void AddFruit(string id, Fruit fruit)         #7
    {
        Fruit.All.Add(id, fruit);
    }
}

Inspect a compact minimal API that maps GET, POST, PUT, and DELETE handlers to a Fruit collection. section 5.2.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Traces simple endpoint mappings and the read-modify-save update procedure, while deferring relationship updates and broader production concerns.
Examples
Uses a Fruit dictionary API and an EF Core recipe service to demonstrate endpoint handlers, updates, and soft deletion.
What you can do after
Apply CRUD through minimal API handlers or EF Core services, including a read-modify-save update workflow.
How it connects
Connects HTTP verbs, minimal APIs, JSON request bodies, Entity Framework Core, service layers, and business logic.

Also explained in

Compare how 11 books explain CRUD →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.