Xpandables.Rests
10.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Xpandables.Rests --version 10.0.1
NuGet\Install-Package Xpandables.Rests -Version 10.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xpandables.Rests" Version="10.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xpandables.Rests" Version="10.0.1" />
<PackageReference Include="Xpandables.Rests" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Xpandables.Rests --version 10.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Xpandables.Rests, 10.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Xpandables.Rests@10.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Xpandables.Rests&version=10.0.1
#tool nuget:?package=Xpandables.Rests&version=10.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
System.Rests
Type-safe, attribute-based REST client with automatic request composition, response handling, and interceptors.
Overview
System.Rests provides a type-safe, attribute-based HTTP client for building RESTful API clients. It uses attributes to define endpoints and request types, with automatic request composition, response handling, request/response interceptors, and resilience options.
Built for .NET 10 with full async support.
Features
Core Client
IRestClient— Core HTTP client interface with async supportRestClient— Default implementation with interceptor pipeline
Request/Response Building
IRestRequestBuilder— Build HTTP requests from contextIRestResponseBuilder— Build responses from HTTP messagesRestRequestBuilder— Default request builder with interceptorsRestResponseBuilder— Default response builder with interceptors
REST Attributes
RestGetAttribute— HTTP GET requestsRestPostAttribute— HTTP POST requestsRestPutAttribute— HTTP PUT requestsRestDeleteAttribute— HTTP DELETE requestsRestPatchAttribute— HTTP PATCH requestsIRestAttributeBuilder— Dynamic attribute building
Request Types
IRestRequest— Base request interfaceIRestString— JSON body requestsIRestQueryString— Query parameter requestsIRestPathString— URL path parameter requestsIRestFormUrlEncoded— Form data requestsIRestMultipart— File upload requestsIRestByteArray— Binary data requestsIRestStream— Stream data requestsIRestHeader— Custom header requestsIRestCookie— Cookie requestsIRestBasicAuthentication— Basic auth requestsIRestPatch— JSON Patch requestsIRestMime— MIME type support
Interceptors
IRestRequestInterceptor— Intercept requests before sendingIRestResponseInterceptor— Intercept responses after receivingOrder— Control interceptor execution order
Resilience Options
RestClientOptions— Configure timeout, retry, circuit breaker, loggingRestRetryOptions— Retry policy configurationRestCircuitBreakerOptions— Circuit breaker configurationRestLogLevel— Logging levels
Request Composers
IRestRequestComposer— Compose HTTP request messagesRestStringComposer— JSON body compositionRestQueryStringComposer— Query string compositionRestPathStringComposer— Path parameter compositionRestFormUrlEncodedComposer— Form data compositionRestMultipartComposer— Multipart compositionRestHeaderComposer— Header compositionRestCookieComposer— Cookie compositionRestBasicAuthComposer— Basic auth compositionRestByteArrayComposer— Binary compositionRestStreamComposer— Stream compositionRestPatchComposer— JSON Patch composition
Response Composers
IRestResponseComposer— Compose REST responsesRestResponseResultComposer— Typed result responsesRestResponseContentComposer— Content responsesRestResponseStreamComposer— Stream responsesRestResponseStreamPagedComposer— Paged stream responsesRestResponseNoContentComposer— No content responsesRestResponseFailureComposer— Error responses
Other Types
RestRequest— Request wrapperRestResponse— Response wrapper with typed resultRestRequestContext— Request building contextRestResponseContext— Response building contextRestSettings— Global settingsRestAttributeProvider— Attribute resolutionRestAuthorizationHandler— Authorization handling
Installation
dotnet add package Xpandables.Rests
Quick Start
Register Services
using Microsoft.Extensions.DependencyInjection;
services.AddXRestAttributeProvider();
services.AddXRestRequestComposers();
services.AddXRestResponseComposers();
services.AddXRestRequestBuilder();
services.AddXRestResponseBuilder();
services.AddXRestClient((sp, client) =>
{
client.BaseAddress = new Uri("https://api.example.com");
});
Define REST Requests
using System.Rests.Abstractions;
// GET with path parameters
public sealed record GetUserRequest(Guid Id)
: IRestRequest<User>, IRestPathString, IRestAttributeBuilder
{
public IDictionary<string, string> GetPathString() =>
new Dictionary<string, string> { ["id"] = Id.ToString() };
public RestAttribute Build(IServiceProvider sp) =>
new RestGetAttribute("/api/users/{id}");
}
// POST with JSON body
public sealed record CreateUserRequest(string Name, string Email)
: IRestRequest<User>, IRestString, IRestAttributeBuilder
{
public RestAttribute Build(IServiceProvider sp) =>
new RestPostAttribute("/api/users");
}
Use the Client
public class UserService(IRestClient client)
{
public async Task<User?> GetUserAsync(Guid id, CancellationToken ct)
{
RestResponse response = await client.SendAsync(new GetUserRequest(id), ct);
if (response.IsSuccess)
{
return response.ToRestResponse<User>().Result;
}
return null;
}
}
Add Request Interceptor
public class LoggingInterceptor : IRestRequestInterceptor
{
public int Order => 0;
public ValueTask InterceptAsync(RestRequestContext context, CancellationToken ct)
{
Console.WriteLine($"Sending: {context.Message.RequestUri}");
return ValueTask.CompletedTask;
}
}
// Register
services.AddSingleton<IRestRequestInterceptor, LoggingInterceptor>();
Add Response Interceptor
public class MetricsInterceptor : IRestResponseInterceptor
{
public int Order => 0;
public ValueTask<RestResponse> InterceptAsync(
RestResponseContext context,
RestResponse response,
CancellationToken ct)
{
Console.WriteLine($"Status: {response.StatusCode}");
return ValueTask.FromResult(response);
}
}
Configure Resilience
services.ConfigureXRestClientOptions(options =>
{
options.Timeout = TimeSpan.FromSeconds(30);
options.Retry = new RestRetryOptions
{
MaxRetryAttempts = 3,
UseExponentialBackoff = true
};
options.CircuitBreaker = new RestCircuitBreakerOptions
{
FailureThreshold = 5,
BreakDuration = TimeSpan.FromSeconds(30)
};
});
Core Types
| Type | Description |
|---|---|
IRestClient |
HTTP client interface |
IRestRequest |
Base request interface |
RestAttribute |
Endpoint attribute |
IRestRequestInterceptor |
Request interceptor |
IRestResponseInterceptor |
Response interceptor |
RestResponse |
Response wrapper |
RestClientOptions |
Resilience configuration |
✅ Best Practices
- Use appropriate request interfaces —
IRestStringfor JSON,IRestQueryStringfor GET params - Combine interfaces — A request can implement multiple interfaces (
IRestPathString+IRestString) - Use records — Immutable request types work best
- Dispose responses — Always use
usingwithRestResponse - Handle errors — Check
IsSuccessbefore accessing results - Configure timeouts — Set appropriate timeouts for your API
📚 Related Packages
- Xpandables.Results — Result types for response handling
- Xpandables.AspNetCore — ASP.NET Core integration
📄 License
Apache License 2.0 — Copyright © Kamersoft 2025
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Configuration (>= 10.0.3)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.3)
- Microsoft.Extensions.Configuration.Json (>= 10.0.3)
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Http (>= 10.0.3)
- Microsoft.Extensions.Http.Resilience (>= 10.3.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- Microsoft.Extensions.Primitives (>= 10.0.3)
- Xpandables.AsyncPaged.Json (>= 10.0.1)
- Xpandables.Primitives (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.