Precept 0.14.0

Precept.Api

HTTP API testing for Precept: a fluent request builder, response assertions, and automatic logging of every request and response into the test's report.

dotnet add package Precept.Api
services.AddPreceptApi();
var response = await Rest.Post("/orders")
    .WithJsonBody(new { sku = "ABC", quantity = 2 })
    .SendAsync();

await Assert.That(response).ToBeSuccessfulAsync();
await Assert.That(response).ToHaveJsonValueAsync("status", "created");
await Assert.That(response).JsonAt("customer.email").ToEndWithAsync("@example.com");
await Assert.That(response).Json<Order>().ToSatisfyAsync(o => o.Lines.Count == 2, "have two lines");

Every failure carries the request line and the response body, because that is always the next question.

The response assertions are ToHaveStatusAsync, ToBeSuccessfulAsync, ToHaveHeaderAsync, ToContainAsync, ToHaveJsonValueAsync, ToHaveXmlValueAsync and ToRespondWithinAsync. JsonAt, Json<T>, XmlAt and Xml<T> narrow to a part of the response so the general assertions apply to it. For an XML API, WithXmlBody writes a [DataContract] type and XmlAt takes an XPath whose prefixes are declared in Api:XmlNamespaces.

Polling for a state that arrives later uses the same sentence under Assert.Eventually:

await Assert.Eventually(() => Rest.Get($"/jobs/{id}").SendAsync())
            .Within(TimeSpan.FromMinutes(2))
            .ToHaveJsonValueAsync("state", "Completed");

Part of Precept, a .NET 10 test framework built on Microsoft.Testing.Platform. Full documentation: assertions on a response · XML · waiting · configuration

Precept 0.14.0 · MIT · © 2026

Esc