RestEase
Dosaic.Extensions.RestEase is an extension library that simplifies HTTP API client creation using RestEase with built-in authentication and retry policies.
Installation
To install the nuget package follow these steps:
dotnet add package Dosaic.Extensions.RestEaseor add as package reference to your .csproj
<PackageReference Include="Dosaic.Extensions.RestEase" Version="" />Usage
The extension provides a factory for creating typed API clients with minimal configuration.
Basic Client Creation
Create a simple API client interface:
using RestEase;
public interface IMyApi
{
[Get("users/{userId}")]
Task<User> GetUserAsync([Path] string userId);
[Post("users")]
Task<User> CreateUserAsync([Body] User user);
}Then create a client instance:
Authentication Support
Create a client with OAuth2 authentication:
Custom Retry Policy
You can specify a custom Polly retry policy:
Advanced Configuration
For complete customization, use all parameters:
Authentication Types
The extension supports these OAuth2 grant types:
Password - username and password authentication
ClientCredentials - client ID and secret authentication
Code - authorization code flow
Default Behavior
By default, the extension uses:
JSON serialization with string enum conversion
A retry policy that retries 2 times for HTTP 5xx errors
Automatic token refresh for authenticated requests
Last updated
