FetchData 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package FetchData --version 0.1.1
NuGet\Install-Package FetchData -Version 0.1.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="FetchData" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FetchData --version 0.1.1
#r "nuget: FetchData, 0.1.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.
// Install FetchData as a Cake Addin
#addin nuget:?package=FetchData&version=0.1.1

// Install FetchData as a Cake Tool
#tool nuget:?package=FetchData&version=0.1.1

Fetch Data

A helper to fetch API services using Refit and Fusillade

NuGet

Configuration

Canfiguration can be done via appsetting.json file on inside code. You can configure host, timeout and serialize mode that represent ApiConfiguration object.

Configure Mail Server

Object of ApiConfiguration

"GitHubService": {
    "host": "https://api.github.com",
    "timeout": 360,
    "serializeMode": "SnakeCase"
}

Configure Interface Modules

You need to define base interface for each module that api services provided, this will enable dependency injection registration on runtime and no need register each Refit interface. To provide it, you can create empty interface, then interit it to each Refit interface services.<br> Interface module:

public interface IGitHub {}

Refit interface that inherit interface module:

[Headers("User-Agent: FetchData-Example")]
public interface IGitHubApi : IGitHub
{
    [Get("/users/{username}")]
    Task<GitHubProfile> GetUser(string username);
}

Configure Dependency Injection Registration

First, you need ApiConfiguration instance before register services,

  • From appsettings.json<br>
    var githubConf = builder.GetSection("GitHubService").Get<ApiConfiguration>();
    
  • From new instance<bR>
    var githubConf = new ApiConfiguration
    {
        Host = "https://api.github.com",
        Timeout = 360,
        SerializeMode = SerializeNamingProperty.SnakeCase
    }
    

Then, create ApiServiceConfiguration instance with previous configuration

var githubServiceConf = new ApiServiceConfiguration
{
    Configuration = githubConf,
    Modules = new[] { typeof(IGitHub) }
};

Register to dependency injection container in Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    // configure api services here

    services.AddApiServices(githubServiceConf);
}

Configure Logging

The default implementation of DelegatingHandler provided this library, will only log http request and response in debug level. To enable it, provide ILoggerFactory to this library.

LoggerFactory
    .Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Debug))
    .SetFetchDataLoggerFactory();

Customize DelegatingHandler

You can provide your own DelegatingHandler implementation to customize authentication header & other stuff, and let FetchData use it. Add your DelegatingHandler before register services to dependency injection.

githubServiceConf.DelegatingHandler = typeof(YourOwnDelegatingHandler);

Usage

FetchData also use Fusillade to drive HttpClient, you can read more about it in here

Get IApiService<T> instance from DI container

var githubService = serviceProvider.GetService<IApiService<IGitHubApi>>();

User Initiated Request

var result = await githubService.Initiated.GetUser(username).ConfigureAwait(false);

Background Request

var result = await githubService.Background.GetUser(username).ConfigureAwait(false);

Speculative Request

var result = await githubService.Speculative.GetUser(username).ConfigureAwait(false);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.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 was computed. 
.NET Framework net461 was computed.  net462 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FetchData:

Package Downloads
TechRedemption.KILS

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.2 673 11/20/2021
0.1.1 375 2/24/2021
0.1.0 309 2/21/2021