Skip to main content

Per-Operation Request Records in C# v4 SDKs (Beta)

· 2 min read

C# v4 SDKs now take one request record per operation. Instead of a long positional parameter list, each endpoint method accepts a {Operation}Request record whose members mirror the operation's parameters and body, so a call reads the same way the API reference does.

Details​

Every operation that takes input gets a public sealed record {Operation}Request. Records for operations on a controller live under Requests/{ApiGroup}/, and records for operations on the client live under Requests/. Path, query and header parameters, the body and every form field become members of the record, named in PascalCase. A JSON, text or binary body is always the Body member.

Required inputs are required members, so a missing required value is a compile error rather than a runtime one. Optional inputs are nullable and are omitted from the request when left unset, inputs with a default keep it unless you override it, and constants are fixed on the record. The record carries the same constraint attributes a model property gets.

The method shape is now Task<T> Op({Op}Request request, RequestOptions? requestOptions = null, CancellationToken cancellationToken = default). An operation with no input has no request parameter. The README, API reference, SDK map and plugin skills all teach the new call shape.

Usage Example​

Build the record with an object initializer, setting members by name:

var orders = await client.Orders.ListOrders(
new ListOrdersRequest
{
CustomerId = "cus_123",
Status = OrderStatus.Shipped,
PerPage = 50,
},
cancellationToken: cancellationToken);

await client.Orders.DeleteOrder(new DeleteOrderRequest { OrderId = "ord_456" });

Pass cancellationToken by name so it never lands in the requestOptions slot.

This change alters every generated call site. Update your calls when you regenerate.

This feature is available in the C# v4 SDK (beta). Generate it from the APIMatic CLI:

apimatic sdk generate --language=csharp --codegen-version=v4 --stability=beta

For the full set of flags and options, see the APIMatic CLI documentation.