Apizr.Tools.NSwag 5.0.0-preview.1

This is a prerelease version of Apizr.Tools.NSwag.
There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global Apizr.Tools.NSwag --version 5.0.0-preview.1
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local Apizr.Tools.NSwag --version 5.0.0-preview.1
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Apizr.Tools.NSwag&version=5.0.0-preview.1&prerelease
nuke :add-package Apizr.Tools.NSwag --version 5.0.0-preview.1

Apizr

Refit based web api client, but resilient (retry, connectivity, cache, auth, log, priority...)

Read - Documentation

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.

Also, we built this lib to make it work with any .Net Standard 2.0 compliant platform, so we could use it seamlessly from any kind of app, with or without DI goodness.

How

An api definition with some attributes:

[assembly:Policy("TransientHttpError")]
namespace Apizr.Sample
{
    [WebApi("https://reqres.in/"), Cache, Log]
    public interface IReqResService
    {
        [Get("/api/users")]
        Task<UserList> GetUsersAsync();

        [Get("/api/users/{userId}")]
        Task<UserDetails> GetUserAsync([CacheKey] int userId);

        [Post("/api/users")]
        Task<User> CreateUser(User user);
    }
}

An instance of this managed api:

// Define some policies
var registry = new PolicyRegistry
{
    {
        "TransientHttpError", 
        HttpPolicyExtensions
            .HandleTransientHttpError()
            .WaitAndRetryAsync(new[]
        {
            TimeSpan.FromSeconds(1),
            TimeSpan.FromSeconds(5),
            TimeSpan.FromSeconds(10)
        })
    }
};

// Get your manager instance
var reqResManager = ApizrBuilder.Current.CreateManagerFor<IReqResService>(
    options => options
        .WithPolicyRegistry(registry)
        .WithAkavacheCacheHandler());

And then you're good to go:

var userList = await reqResManager.ExecuteAsync(api => api.GetUsersAsync());

This request will be managed with the defined policies, data cached, http traces logged.

Apizr has a lot more to offer, just read the doc!

Where

Change Log

Managing (Core)

Project Current Upcoming
Apizr NuGet NuGet Pre Release
Apizr.Extensions.Microsoft.DependencyInjection NuGet NuGet Pre Release

Caching

Project Current Upcoming
Apizr.Extensions.Microsoft.Caching NuGet NuGet Pre Release
Apizr.Integrations.Akavache NuGet NuGet Pre Release
Apizr.Integrations.MonkeyCache NuGet NuGet Pre Release

Handling

Project Current Upcoming
Apizr.Integrations.Fusillade NuGet NuGet Pre Release
Apizr.Integrations.MediatR NuGet NuGet Pre Release
Apizr.Integrations.Optional NuGet NuGet Pre Release

Mapping

Project Current Upcoming
Apizr.Integrations.AutoMapper NuGet NuGet Pre Release

Transferring

Project Current Upcoming
Apizr.Integrations.FileTransfer NuGet NuGet Pre Release
Apizr.Extensions.Microsoft.FileTransfer NuGet NuGet Pre Release
Apizr.Integrations.FileTransfer.MediatR NuGet NuGet Pre Release
Apizr.Integrations.FileTransfer.Optional NuGet NuGet Pre Release

Generating

Project Current Upcoming
Apizr.Tools.NSwag NuGet NuGet Pre Release

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 auto mapping for mediation requests (requires MediatR integration and could work with Optional integration) using AutoMapper
  • 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

Install the NuGet .NET CLI Tool package if needed:

  • Apizr.Tools.NSwag package enables Apizr files generation by command lines (Models, Apis and Registrations) from an OpenApi/Swagger definition using NSwag

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 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)
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
6.0.0-preview.2 39 3/29/2024
6.0.0-preview.1 44 3/8/2024
5.4.0 218 10/12/2023
5.3.0 215 9/25/2023
5.2.0 222 8/28/2023
5.1.0 162 7/21/2023
5.0.1 148 7/16/2023
5.0.0 165 6/22/2023
5.0.0-preview.4 71 6/16/2023
5.0.0-preview.3 71 6/7/2023
5.0.0-preview.2 62 5/16/2023
5.0.0-preview.1 89 3/22/2023