From dotnet-developer
Write a Wolverine HTTP endpoint with pre-conditions, handler, and tests.
npx claudepluginhub hpsgd/turtlestack --plugin dotnet-developerThis skill is limited to using the following tools:
Write a Wolverine endpoint for $ARGUMENTS.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Designs, implements, and audits WCAG 2.2 AA accessible UIs for Web (ARIA/HTML5), iOS (SwiftUI traits), and Android (Compose semantics). Audits code for compliance gaps.
Write a Wolverine endpoint for $ARGUMENTS.
Before writing the endpoint:
Read existing endpoints — find the nearest similar endpoint and match its patterns
find . -name "*.cs" -path "*/Endpoints/*" | head -20
grep -rn "WolverineGet\|WolverinePost\|WolverinePut\|WolverineDelete\|WolverinePatch" --include="*.cs" | head -20
Identify the aggregate — which Marten aggregate does this endpoint operate on?
Identify the URL hierarchy — trace the entity ownership chain to the root
Check for existing commands/events — reuse existing message types where appropriate
URLs MUST mirror entity ownership. No flat top-level listings of child resources.
GET /api/sources → List sources (paginated)
POST /api/sources → Create source
GET /api/sources/{sourceId} → Get source
PATCH /api/sources/{sourceId} → Update source
DELETE /api/sources/{sourceId} → Delete source
GET /api/sources/{sourceId}/crawls → List crawls for source
POST /api/sources/{sourceId}/crawls → Create crawl for source
GET /api/sources/{sourceId}/crawls/{crawlId} → Get specific crawl
Rules:
/sources, not /source{sourceId}, not {id} (disambiguates in nested routes)POST /sources/{id}/crawls not POST /sources/{id}/triggerCrawlpublic static class CreateSourceEndpoint
{
// Pre-condition: validate, load dependencies, check authorisation
// Returns ProblemDetails to short-circuit with an error response
// Returns null to proceed to Handle
public static async Task<ProblemDetails?> LoadAsync(
CreateSourceCommand command,
IDocumentSession session,
CancellationToken ct)
{
// Validate business rules that require database access
var exists = await session.Query<Source>()
.AnyAsync(s => s.Name == command.Name, ct);
if (exists)
{
return new ProblemDetails
{
Title = "Source already exists",
Detail = $"A source with name '{command.Name}' already exists.",
Status = 409
};
}
return null; // Proceed to Handle
}
// Handler: pure business logic, returns events as cascading messages
[WolverinePost("/api/sources")]
public static SourceCreated Handle(CreateSourceCommand command)
{
var source = new Source
{
Id = CombGuidIdGeneration.NewGuid(),
Name = command.Name,
Url = command.Url,
CreatedAt = DateTimeOffset.UtcNow
};
return new SourceCreated(source.Id, source.Name);
}
}
LoadAsync rules:
Task<ProblemDetails?> — null means "proceed", non-null means "stop with this error"IDocumentSession, CancellationToken, and any services needed for validationHandle rules:
object? for polymorphic cascade)public static class GetSourceEndpoint
{
[WolverineGet("/api/sources/{sourceId}")]
public static async Task<IResult> Handle(
Guid sourceId,
IQuerySession session,
CancellationToken ct)
{
var source = await session.LoadAsync<Source>(sourceId, ct);
return source is not null
? Results.Ok(source.ToResponse())
: Results.NotFound();
}
}
Rules:
IQuerySession (read-only) not IDocumentSession (read-write) for queriesIResult to control HTTP status codespublic static class ListSourceCrawlsEndpoint
{
public record ListCrawlsRequest(
Guid SourceId,
int Page = 1,
int Size = 25,
string? Sort = "createdAt",
string? Dir = "desc",
string? Q = null);
[WolverineGet("/api/sources/{sourceId}/crawls")]
public static async Task<PagedResult<CrawlResponse>> Handle(
[AsParameters] ListCrawlsRequest request,
IQuerySession session,
CancellationToken ct)
{
var query = session.Query<Crawl>()
.Where(c => c.SourceId == request.SourceId);
if (!string.IsNullOrWhiteSpace(request.Q))
{
query = query.Where(c => c.Name.Contains(request.Q));
}
query = request.Sort switch
{
"name" => request.Dir == "asc"
? query.OrderBy(c => c.Name)
: query.OrderByDescending(c => c.Name),
_ => request.Dir == "asc"
? query.OrderBy(c => c.CreatedAt)
: query.OrderByDescending(c => c.CreatedAt)
};
var totalItems = await query.CountAsync(ct);
var items = await query
.Skip((request.Page - 1) * request.Size)
.Take(request.Size)
.ToListAsync(ct);
return new PagedResult<CrawlResponse>(
items.Select(c => c.ToResponse()).ToList(),
request.Page,
request.Size,
totalItems);
}
}
List endpoint rules:
page, size, sort, dir, q (text search)PagedResult<T> with items, page, size, totalItems, totalPagescreatedAt desc for time-based, name asc for alphabetical)// Command — what the caller wants to happen
public record CreateSourceCommand(
string Name,
string Url);
// Event — what happened (past tense, immutable)
public record SourceCreated(
Guid SourceId,
string Name);
// Response DTO — what the caller sees
public record SourceResponse(
Guid Id,
string Name,
string Url,
DateTimeOffset CreatedAt,
DateTimeOffset? LastUpdatedAt);
Rules:
CreateSource, UpdateCrawlSettings)SourceCreated, CrawlSettingsUpdated)LastUpdatedAt on every response for optimistic concurrencypublic static class UpdateSourceEndpoint
{
public static async Task<ProblemDetails?> LoadAsync(
UpdateSourceCommand command,
IDocumentSession session,
CancellationToken ct)
{
var source = await session.LoadAsync<Source>(command.SourceId, ct);
if (source is null)
return new ProblemDetails { Status = 404, Title = "Source not found" };
if (source.LastUpdatedAt != command.LastUpdatedAt)
return new ProblemDetails
{
Status = 409,
Title = "Conflict",
Detail = "The resource was modified by another request. Please re-fetch and retry."
};
return null;
}
[WolverinePatch("/api/sources/{sourceId}")]
public static SourceUpdated Handle(UpdateSourceCommand command, Source source)
{
// Apply changes using RFC 7396 merge semantics
if (command.Name is not null) source.Name = command.Name;
if (command.Url is not null) source.Url = command.Url;
source.LastUpdatedAt = DateTimeOffset.UtcNow;
return new SourceUpdated(source.Id);
}
}
public class WhenCreatingASource
{
[Fact]
public void it_returns_a_source_created_event()
{
// Arrange
var command = new CreateSourceCommand("Test Source", "https://example.com");
// Act
var result = CreateSourceEndpoint.Handle(command);
// Assert
result.ShouldNotBeNull();
result.Name.ShouldBe("Test Source");
}
}
public class CreateSourceIntegrationTest : IntegrationContext
{
[Fact]
public async Task it_creates_a_source_and_returns_201()
{
// Arrange
var command = new CreateSourceCommand("Test Source", "https://example.com");
// Act
var result = await Host.Scenario(s =>
{
s.Post.Json(command).ToUrl("/api/sources");
s.StatusCodeShouldBe(201);
});
// Assert
var response = result.ReadAsJson<SourceResponse>();
response.ShouldNotBeNull();
response.Name.ShouldBe("Test Source");
}
[Fact]
public async Task it_returns_409_when_source_name_already_exists()
{
// Arrange — create existing source
await Host.Scenario(s =>
{
s.Post.Json(new CreateSourceCommand("Duplicate", "https://a.com")).ToUrl("/api/sources");
s.StatusCodeShouldBe(201);
});
// Act — try to create another with same name
await Host.Scenario(s =>
{
s.Post.Json(new CreateSourceCommand("Duplicate", "https://b.com")).ToUrl("/api/sources");
s.StatusCodeShouldBe(409);
});
}
}
Testing rules:
WhenCreatingASource, GivenAnExistingSourceSubstitute.For<T>()ShouldBe, ShouldNotBeNull, ShouldThrow/crawls/{id} without the parent /sources/{sourceId}/crawls/{id}lastUpdatedAt allows silent overwritesDeliver:
/dotnet-developer:write-handler — endpoints delegate to handlers. Write the endpoint first (HTTP contract), then the handler (business logic).