AspNetForge.Web 1.2.1

dotnet add package AspNetForge.Web --version 1.2.1
                    
NuGet\Install-Package AspNetForge.Web -Version 1.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspNetForge.Web" Version="1.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspNetForge.Web" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="AspNetForge.Web" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AspNetForge.Web --version 1.2.1
                    
#r "nuget: AspNetForge.Web, 1.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AspNetForge.Web@1.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AspNetForge.Web&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=AspNetForge.Web&version=1.2.1
                    
Install as a Cake Tool

AspNetForge.Web

Generic extension methods for ASP.NET Core Minimal API with Entity Framework Core.

Overview

AspNetForge.Web provides a set of generic extension methods that register standard CRUD (Create, Read, Update, Delete) endpoints for Entity Framework Core entities in ASP.NET Core Minimal API applications.

Installation

dotnet add package AspNetForge.Web

Dependencies

  • Microsoft.EntityFrameworkCore (>= 8.0.0)
  • Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 8.0.27)

Usage

Define your models and DbContext

public class Product
{
    public int Id { get; set; }
    public required string Name { get; set; }
    public required string Article { get; set; }
    public required decimal MinCost { get; set; }
}

public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
    public DbSet<Product> Products { get; set; }
}

Register endpoints in Program.cs

using AspNetForge.Web.Extensions;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

var app = builder.Build();

app.UseDefaultFiles();
app.UseStaticFiles();

// Register CRUD endpoints for each entity
app.MapCrud<Product, AppDbContext>("/api/products");

app.Run();

This single line registers five endpoints:

Method Route Description
GET /api/products Get all entities
GET /api/products/{id} Get entity by ID
POST /api/products Create new entity
PUT /api/products/{id} Update entity by ID
DELETE /api/products/{id} Delete entity by ID

Custom endpoints

MapCrud covers the standard operations. For custom logic, add endpoints manually as usual:

app.MapCrud<Product, AppDbContext>("/api/products");

// Custom endpoint alongside generated CRUD
app.MapGet("/api/products/search", async (string query, AppDbContext db) =>
    await db.Products.Where(p => p.Name.Contains(query)).ToListAsync());

JavaScript REST client

The package includes an embedded CrudClient JavaScript module for interacting with the registered endpoints from the browser.

Extract it to wwwroot/js/ in Program.cs:

app.UseForgeResources();
app.UseDefaultFiles();
app.UseStaticFiles();

Then reference it in your HTML:

<script src="/js/crud.js"></script>
<script>
    const api = new CrudClient('/api/products');

    // GET all
    const products = await api.getAll();

    // POST
    const created = await api.create({ name: 'Item', article: 'A-01', minCost: 100 });

    // PUT
    const updated = await api.update(1, { name: 'Updated', article: 'A-01', minCost: 150 });

    // DELETE
    await api.remove(1);
</script>

API Reference

MapCrud<TEntity, TContext>(this WebApplication app, string route)

Registers GET (all), GET (by id), POST, PUT, DELETE endpoints for the given entity type.

Type parameters:

  • TEntity — Entity class with an int Id property
  • TContextDbContext class containing a DbSet<TEntity>

Parameters:

  • route — Base route path (e.g. "/api/products")

Returns: WebApplication (for chaining)

UseForgeResources(this WebApplication app, bool overwrite = false)

Extracts embedded JavaScript resources to wwwroot/js/.

CrudClient (JavaScript)

Client-side class for REST API interaction via Fetch API.

Method Returns Description
getAll() Promise<T[]> GET all entities
getById(id) Promise<T\|null> GET entity by ID
create(entity) Promise<T> POST new entity
update(id, entity) Promise<T\|null> PUT update entity
remove(id) Promise<boolean> DELETE entity

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 91 5/23/2026
1.2.0 82 5/23/2026
1.0.0 86 5/22/2026