Apizr 6.0.0-preview.8
See the version list below for details.
dotnet add package Apizr --version 6.0.0-preview.8
NuGet\Install-Package Apizr -Version 6.0.0-preview.8
<PackageReference Include="Apizr" Version="6.0.0-preview.8" />
paket add Apizr --version 6.0.0-preview.8
#r "nuget: Apizr, 6.0.0-preview.8"
// Install Apizr as a Cake Addin #addin nuget:?package=Apizr&version=6.0.0-preview.8&prerelease // Install Apizr as a Cake Tool #tool nuget:?package=Apizr&version=6.0.0-preview.8&prerelease
Apizr
Refit based web api client, but resilient (retry, connectivity, cache, auth, log, priority...)
What
The Apizr project was motivated by this 2015 famous blog post about resilient networking.
Its main focus was to address at least everything explained into this article, meanning:
- Easy access to restful services
- Work offline with cache management
- Handle errors with retry pattern and global catching
- Handle request priority
- Check connectivity
- Fast development time
- Easy maintenance
- Reuse existing libraries
But also, some more core features like:
- Trace http traffic
- Handle authentication
And more integration/extension independent optional features like:
- Choose cache, log and connectivity providers
- Register it as an MS DI extension
- Map model with DTO
- Use Mediator pattern
- Use Optional pattern
- Manage file transfers
The list is not exhaustive, there’s more, but what we wanted was playing with all of it with as less code as we could, not worrying about plumbing things and being sure everything is wired and handled by design or almost.
Inspired by Refit.Insane.PowerPack, we wanted to make it simple to use, mixing attribute decorations and fluent configuration.
How
An api definition with some attributes:
// (Polly) Define a resilience pipeline key
[assembly:ResiliencePipeline("TransientHttpError")]
namespace Apizr.Sample
{
// (Apizr) Define your web api base url and ask for cache and logs
[BaseAddress("https://reqres.in/"),
Cache(CacheMode.GetAndFetch, "01:00:00"),
Log(HttpMessageParts.AllButBodies)]
public interface IReqResService
{
// (Refit) Define your web api interface methods
[Get("/api/users")]
Task<UserList> GetUsersAsync([RequestOptions] IApizrRequestOptions options);
[Get("/api/users/{userId}")]
Task<UserDetails> GetUserAsync([CacheKey] int userId, [RequestOptions] IApizrRequestOptions options);
[Post("/api/users")]
Task<User> CreateUser(User user, [RequestOptions] IApizrRequestOptions options);
}
}
Some resilience strategies:
// (Polly) Create a resilience pipeline with some strategies
var resiliencePipelineBuilder = new ResiliencePipelineBuilder<HttpResponseMessage>()
// Configure telemetry to get some logs from Polly process
.ConfigureTelemetry(LoggerFactory.Create(loggingBuilder =>
loggingBuilder.Debug()))
// Add a retry strategy with some options
.AddRetry(
new RetryStrategyOptions<HttpResponseMessage>
{
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
.Handle<HttpRequestException>()
.HandleResult(response =>
response.StatusCode is >= HttpStatusCode.InternalServerError
or HttpStatusCode.RequestTimeout),
Delay = TimeSpan.FromSeconds(1),
MaxRetryAttempts = 3,
UseJitter = true,
BackoffType = DelayBackoffType.Exponential
}));
An instance of this managed api:
Static
Relies on static builder instantiation approach.
// (Polly) Add the resilience pipeline with its key to a registry
var resiliencePipelineRegistry = new ResiliencePipelineRegistry<string>();
resiliencePipelineRegistry.TryAddBuilder<HttpResponseMessage>("TransientHttpError",
(builder, _) => builder.AddPipeline(resiliencePipelineBuilder.Build()));
// (Apizr) Get your manager instance
var reqResManager = ApizrBuilder.Current.CreateManagerFor<IReqResService>(
options => options
// With a logger
.WithLoggerFactory(LoggerFactory.Create(loggingBuilder =>
loggingBuilder.Debug()))
// With the defined resilience pipeline registry
.WithResiliencePipelineRegistry(resiliencePipelineRegistry)
// And with a cache handler
.WithAkavacheCacheHandler());
Extended
Relies on IServiceCollection
extension methods approach.
// (Logger) Configure logging the way you want, like
services.AddLogging(loggingBuilder => loggingBuilder.AddDebug());
// (Apizr) Add an Apizr manager for the defined api to your container
services.AddApizrManagerFor<IReqResService>(options =>
// With a cache handler
options.WithAkavacheCacheHandler());
// (Polly) Add the resilience pipeline with its key to your container
services.AddResiliencePipeline<string, HttpResponseMessage>("TransientHttpError",
builder => builder.AddPipeline(resiliencePipelineBuilder.Build()));
...
// (Apizr) Get your manager instance the way you want, like
var reqResManager = serviceProvider.GetRequiredService<IApizrManager<IReqResService>>();
And then you're good to go:
var userList = await reqResManager.ExecuteAsync((api, opt) => api.GetUsersAsync(opt));
This request will be managed with the defined resilience strategies, data cached and all logged.
Apizr has a lot more to offer, just read the doc!
Where
- Please read the Change Log to get a picture of what's in.
- Please read the Breaking changes to get a picture of what's changed.
Managing (Core)
Project | Current | Upcoming |
---|---|---|
Apizr | ||
Apizr.Extensions.Microsoft.DependencyInjection |
Caching
Project | Current | Upcoming |
---|---|---|
Apizr.Extensions.Microsoft.Caching | ||
Apizr.Integrations.Akavache | ||
Apizr.Integrations.MonkeyCache |
Handling
Project | Current | Upcoming |
---|---|---|
Apizr.Integrations.Fusillade | ||
Apizr.Integrations.MediatR | ||
Apizr.Integrations.Optional |
Mapping
Project | Current | Upcoming |
---|---|---|
Apizr.Integrations.AutoMapper | ||
Apizr.Integrations.Mapster |
Transferring
Project | Current | Upcoming |
---|---|---|
Apizr.Integrations.FileTransfer | ||
Apizr.Extensions.Microsoft.FileTransfer | ||
Apizr.Integrations.FileTransfer.MediatR | ||
Apizr.Integrations.FileTransfer.Optional |
Generating
Project | Current | Upcoming |
---|---|---|
Refitter | ||
Refitter.SourceGenerator |
Install the NuGet reference package of your choice:
- Apizr package comes with the static builder instantiation approach (which you can register in your DI container then)
- Apizr.Extensions.Microsoft.DependencyInjection package extends your IServiceCollection with AddApizr, AddApizrFor and AddApizrCrudFor registration methods
- Apizr.Extensions.Microsoft.Caching package brings an ICacheHandler method mapping implementation for MS Extensions Caching
- Apizr.Integrations.Akavache package brings an ICacheHandler method mapping implementation for Akavache
- Apizr.Integrations.MonkeyCache package brings an ICacheHandler method mapping implementation for MonkeyCache
- Apizr.Integrations.Fusillade package enables request priority management using Fusillade
- Apizr.Integrations.MediatR package enables request auto handling with mediation using MediatR
- Apizr.Integrations.Optional package enables Optional result from mediation requests (requires MediatR integration) using Optional.Async
- Apizr.Integrations.AutoMapper package enables data mapping using AutoMapper
- Apizr.Integrations.Mapster package enables data mapping using Mapster
- Apizr.Integrations.FileTransfer package enables file transfer management for static registration
- Apizr.Extensions.Microsoft.FileTransfer package enables file transfer management for extended registration
- Apizr.Integrations.FileTransfer.MediatR package enables file transfer management for mediation requests (requires MediatR integration and could work with Optional integration) using MediatR
- Apizr.Integrations.FileTransfer.Optional package enables file transfer management for mediation requests with optional result (requires MediatR integration and could work with Optional integration) using Optional.Async
Choose which generating approach suites to your needs by installing either:
- Refitter .NET CLI Tool distributed via nuget.org that outputs a single C# file on disk
- Refiiter C# Source Generator via the Refitter.SourceGenerator package that generates code on compile time based on a .refitter within the project directory.
Apizr core package make use of well known nuget packages to make the magic appear:
Package | Features |
---|---|
Refit | Auto-implement web api interface and deal with HttpClient |
Polly.Extensions | Apply some policies like Retry, CircuitBreaker, etc... |
Microsoft.Extensions.Logging.Abstractions | Delegate logging layer to MS Extensions Logging |
It also comes with some handling interfaces to let you provide your own services for:
- Caching with ICacheHandler, which comes with its default VoidCacheHandler (no cache), but also with:
- InMemoryCacheHandler & DistributedCacheHandler: MS Extensions Caching methods mapping interface (Integration package referenced above), meaning you can provide any compatible caching engine
- AkavacheCacheHandler: Akavache methods mapping interface (Integration package referenced above)
- MonkeyCacheHandler: MonkeyCache methods mapping interface (Integration package referenced above)
- Logging As Apizr relies on official MS ILogger interface, you may want to provide any compatible logging engine (built-in DebugLogger activated by default)
- Connectivity with IConnectivityHandler, which comes with its default VoidConnectivityHandler (no connectivity check)
- Mapping with IMappingHandler, which comes with its default VoidMappingHandler (no mapping conversion), but also with:
- AutoMapperMappingHandler: AutoMapper mapping methods mapping interface (Integration package referenced above)
- MapsterMappingHandler: Mapster mapping methods mapping interface (Integration package referenced above)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
- Polly.Extensions (>= 8.3.0)
- Refit (>= 7.0.0)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Apizr:
Package | Downloads |
---|---|
Apizr.Extensions.Microsoft.DependencyInjection
Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority...) |
|
Apizr.Integrations.Akavache
Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority...) |
|
Apizr.Integrations.AutoMapper
Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority...) |
|
Apizr.Integrations.MonkeyCache
Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority...) |
|
Apizr.Integrations.Fusillade
Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority...) |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.4.1 | 221 | 12/18/2024 |
6.4.0 | 1,184 | 11/22/2024 |
6.4.0-preview.4 | 64 | 11/19/2024 |
6.4.0-preview.3 | 61 | 11/14/2024 |
6.4.0-preview.2 | 159 | 11/6/2024 |
6.4.0-preview.1 | 65 | 10/25/2024 |
6.3.0 | 1,329 | 10/17/2024 |
6.2.0 | 514 | 10/11/2024 |
6.1.0 | 703 | 10/1/2024 |
6.0.0 | 945 | 9/10/2024 |
6.0.0-preview.9 | 67 | 8/29/2024 |
6.0.0-preview.8 | 63 | 8/3/2024 |
6.0.0-preview.7 | 698 | 7/25/2024 |
6.0.0-preview.6 | 74 | 7/18/2024 |
6.0.0-preview.5 | 94 | 6/24/2024 |
6.0.0-preview.4 | 107 | 5/24/2024 |
6.0.0-preview.3 | 2,671 | 5/2/2024 |
6.0.0-preview.2 | 261 | 3/29/2024 |
6.0.0-preview.1 | 88 | 3/8/2024 |
5.4.0 | 1,434 | 10/12/2023 |
5.3.0 | 1,086 | 9/25/2023 |
5.2.0 | 1,098 | 8/28/2023 |
5.1.0 | 1,221 | 7/21/2023 |
5.0.1 | 1,293 | 7/16/2023 |
5.0.0 | 1,611 | 6/22/2023 |
5.0.0-preview.4 | 106 | 6/16/2023 |
5.0.0-preview.3 | 103 | 6/7/2023 |
5.0.0-preview.2 | 107 | 5/16/2023 |
5.0.0-preview.1 | 115 | 3/22/2023 |
4.1.0 | 4,541 | 5/2/2022 |
4.0.0 | 5,216 | 3/30/2022 |
4.0.0-preview.2 | 163 | 3/15/2022 |
4.0.0-preview.1 | 154 | 2/15/2022 |
3.0.0 | 3,058 | 3/12/2021 |
2.0.0 | 2,083 | 1/4/2021 |
1.9.0 | 2,122 | 11/19/2020 |
1.8.1 | 2,122 | 10/22/2020 |
1.8.0 | 2,129 | 10/22/2020 |
1.7.0 | 2,179 | 10/19/2020 |
1.6.0 | 2,218 | 10/9/2020 |
1.5.0 | 2,229 | 7/31/2020 |
1.4.2 | 2,152 | 7/24/2020 |
1.4.1 | 2,206 | 7/21/2020 |
1.4.0 | 2,169 | 7/17/2020 |
1.3.0 | 2,187 | 7/9/2020 |
1.2.0 | 1,978 | 7/3/2020 |
1.1.0 | 1,661 | 6/22/2020 |
1.0.0 | 1,664 | 6/17/2020 |