Genocs.WebApi

Genocs.WebApi — Agent Reference Documentation

Consumer Mode for Agents

  • Assume package is installed from NuGet.
  • Do not rely on repository source code access.
  • Prefer stable public APIs and extension methods documented here.
  • If behavior is uncertain, fail safely and request package version and configuration details.

Purpose

Genocs.WebApi provides API bootstrap conventions, endpoint composition helpers, request/response utilities, and optional exception-to-response middleware for ASP.NET Core hosts.

Quick Facts

KeyValue
PackageGenocs.WebApi
Target frameworksnet10.0, net9.0, net8.0
Primary roleWeb API conventions and endpoint DSL
Main APIsAddWebApi, UseEndpoints, AddErrorHandler<T>, UseErrorHandler, UseAllForwardedHeaders

Install

dotnet add package Genocs.WebApi

Minimal Integration Recipe (Program.cs)

using Genocs.Core.Builders;
using Genocs.WebApi;

IGenocsBuilder gnxBuilder = builder.AddGenocs();
gnxBuilder.AddWebApi();
gnxBuilder.Build();

var app = builder.Build();

app.UseEndpoints(endpoints =>
{
    endpoints.Get("/health", async ctx => await ctx.Response.Ok(new { status = "ok" }));
});

app.Run();

Configuration

Genocs.WebApi exposes a minimal webApi section through WebApiOptions.

{
  "webApi": {
    "bindRequestFromRoute": true
  }
}
SettingTypeDescription
bindRequestFromRouteboolWhen enabled, request-binding helpers can hydrate request objects from route values in addition to the request body.

Dependencies

  • Genocs.Core
  • ASP.NET Core shared framework (Microsoft.AspNetCore.App)

Troubleshooting

  1. Endpoints do not respond after startup. Fix: Ensure UseEndpoints(...) is called after builder.Build() and before app.Run().
  2. Unhandled exceptions return default responses. Fix: Register a mapper with AddErrorHandler<T>() and add UseErrorHandler() to the pipeline.