Skip to main content

Parameters

Path parameters

Named in the route template with {name}. The method parameter with the same name is substituted:

[Get("/users/{id}")]
Task<UserDto> GetUserAsync(int id, CancellationToken ct = default);

Query parameters

Decorated with [Query]. They are appended to the URL as ?name=value:

[Get("/users")]
Task<List<UserDto>> ListUsersAsync([Query] string? name = null, CancellationToken ct = default);
// → GET /users?name=Alice

Nullable query parameters (string?, int?) are omitted from the URL when null.

Multiple query parameters:

[Get("/products")]
Task<List<ProductDto>> SearchAsync(
[Query] string? category,
[Query] int? maxPrice,
CancellationToken ct = default);
// → GET /products?category=Books&maxPrice=50

Request body

Decorated with [Body]. The object is serialized by the configured IRestSerializer and sent as the request body with the appropriate Content-Type:

[Post("/users")]
Task<UserDto> CreateUserAsync([Body] CreateUserRequest body, CancellationToken ct = default);

Only one [Body] parameter per method is supported.

Header parameters

Decorated with [Header("Header-Name")]. The value is added to the request headers:

[Get("/secure/resource")]
Task<ResourceDto> GetSecureAsync([Header("X-Api-Key")] string apiKey, CancellationToken ct = default);

The header name in the attribute is the exact HTTP header name sent over the wire.

CancellationToken

Every method should end with CancellationToken ct = default. The generator recognises this type by its well-known name and passes it to HttpClient.SendAsync.

Summary table

AnnotationWhereNotes
{name} in routeURL path segmentURL-encoded automatically
[Query]Query stringNullable → omitted when null
[Body]Request bodySerialized by IRestSerializer
[Header("Name")]Request headerExact header name required
CancellationToken(automatic)Recognised by type, no attribute needed