Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Core.WebApi

NuGet .NET

Provides ASP.NET Core Web API utilities including base controller classes, standardized response wrappers, and DI registration helpers to reduce boilerplate in every microservice's API layer.


Features

  • BaseController — pre-configured ControllerBase with built-in dispatcher injection
  • Standardized ApiResponse<T> wrapper for consistent JSON envelopes
  • Service collection extensions to wire up Web API concerns in one call
  • Claim resolution helpers bridging Core.Security with IHttpContextAccessor

Installation

<PackageReference Include="Core.WebApi" Version="3.0.3" />

Setup

// Program.cs
builder.Services.AddCoreWebApi();

// or configure manually
builder.Services.AddControllers();
builder.Services.AddHttpContextAccessor();

Usage

BaseController

[Route("api/[controller]")]
public class OrdersController : BaseController
{
    [HttpPost]
    public async Task<IActionResult> Create([FromBody] CreateOrderCommand command)
    {
        // Dispatcher is available via the base class
        var orderId = await Dispatcher.SendAsync(command);
        return CreatedAtAction(nameof(GetById), new { id = orderId }, null);
    }

    [HttpGet("{id:guid}")]
    public async Task<IActionResult> GetById(Guid id)
    {
        var order = await Dispatcher.QueryAsync(new GetOrderQuery(id));
        return Ok(order);
    }
}

Standardized API Response

// Returns: { "data": { ... }, "success": true, "errors": [] }
return Ok(ApiResponse.Success(result));

// Returns: { "data": null, "success": false, "errors": ["Not found"] }
return NotFound(ApiResponse.Fail("Order not found"));

Dependencies

Package Version
Core.Abstractions 3.1.9
Core.Security.Domain 3.0.1
Core.Security.Extensions 3.0.0
Microsoft.AspNetCore.Mvc.Core (framework)

Related Packages