API Endpoints for stevedunn/vogen
Routes in the stevedunn/vogen
codebase are defined within ASP.NET Core controller classes, specifically through the use of attributes such as [Route]
, [HttpGet]
, and other HTTP verb decorators. The following illustrates the routes associated with a sample controller, OrdersController
, as found in the codebase.
OrdersController Implementation
The OrdersController
handles HTTP requests related to orders and defines several routes:
[Route("api/[controller]")] public class OrdersController : ControllerBase { private static readonly Order[] _orders = [ new() { OrderId = OrderId.From(1), CustomerName = CustomerName.From("Fred") }, new() { OrderId = OrderId.From(2), CustomerName = CustomerName.From("Barney") } ];
[HttpGet] public IActionResult CurrentOrders() { return Ok(_orders); }
[HttpGet, Route("customer/{customerName}")] public IActionResult GetByName(CustomerName customerName) { return Ok(_orders.Where(o => o.CustomerName == customerName)); }
[HttpGet, Route("{orderId}")] public IActionResult GetByOrderId(OrderId orderId) { return Ok(_orders.Where(o => o.OrderId == orderId)); } }
Defined Routes
Base Route for Orders
- HTTP Method: GET
- Route:
api/orders
- Action: Returns the current list of orders.
Get Orders by Customer Name
- HTTP Method: GET
- Route:
api/orders/customer/{customerName}
- Action: Retrieves orders that belong to a specific customer, where
{customerName}
is a route parameter.
Get Order by Order ID
- HTTP Method: GET
- Route:
api/orders/{orderId}
- Action: Retrieves a specific order by its ID, where
{orderId}
is a route parameter.
Type Conversion
In this implementation, CustomerName
and OrderId
are value objects defined using Vogen, which automatically generates type converters allowing for seamless integration in the ASP.NET Core routing pipeline. For instance, when the routing framework processes the request for GetByName
, it looks for a CustomerName
type that matches the incoming {customerName}
string parameter:
public IActionResult GetByName(CustomerName customerName)
{
return Ok(_orders.Where(o => o.CustomerName == customerName));
}
Source of Information
This routing mechanism, along with the handling of value objects, is detailed in the project files, particularly within the context of the ASP.NET Core integration of the Vogen library. The attribute usage clearly defines how routes are constructed and mapped to specific controller actions.
This information is derived from the provided source files, specifically from the implementation found in samples/WebApplication/OrdersController.cs
.
Sources
- samples/WebApplication/OrdersController.cs
- src/Vogen/MethodDiscovery.cs
- tests/AnalyzerTests/DoNotUseNewAnalyzerTests.cs
- src/Vogen.CodeFixers/obj/Vogen.CodeFixers.csproj.nuget.dgspec.json
- src/obj/Debug/netstandard2.0/Vogen.Pack.AssemblyInfo.cs
- src/Vogen/DiscoverUserProvidedOverloads.cs
- samples/Onion/Infra/obj/Infra.csproj.nuget.dgspec.json
- samples/Onion/Domain/obj/Domain.csproj.nuget.dgspec.json