xabluhq - Xablu.WebApiClient 0.10.0-unstable0003

The Xablu WebApiClient is a C# HTTP library which aims to simplify consuming of Web API services in .NET projects.

PM> Install-Package Xablu.WebApiClient -Version 0.10.0-unstable0003 -Source https://www.myget.org/F/xabluhq/api/v3/index.json

Copy to clipboard

> nuget.exe install Xablu.WebApiClient -Version 0.10.0-unstable0003 -Source https://www.myget.org/F/xabluhq/api/v3/index.json

Copy to clipboard

> dotnet add package Xablu.WebApiClient --version 0.10.0-unstable0003 --source https://www.myget.org/F/xabluhq/api/v3/index.json

Copy to clipboard
<PackageReference Include="Xablu.WebApiClient" Version="0.10.0-unstable0003" />
Copy to clipboard
source https://www.myget.org/F/xabluhq/api/v3/index.json

nuget Xablu.WebApiClient  ~> 0.10.0-unstable0003
Copy to clipboard

> choco install Xablu.WebApiClient --version 0.10.0-unstable0003 --source https://www.myget.org/F/xabluhq/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "xabluhq" -SourceLocation "https://www.myget.org/F/xabluhq/api/v2"
Install-Module -Name "Xablu.WebApiClient" -RequiredVersion "0.10.0-unstable0003" -Repository "xabluhq" -AllowPreRelease
Copy to clipboard

xablu logo

Xablu.WebApiClient

The Xablu WebApiClient is a C# HTTP library which aims to simplify consuming of REST / GraphQL API services in .NET projects.

:construction: :warning: Already using this library?
We have been working on a 2nd version of WebApiClient which is based on Refit and will support GraphQL. This version has may new features. Beware, upgrading from version 1 to version 2 has some breaking changes since it’s not backwards compatible.

Build Status Github tag NuGet

Table of contents

  1. How Xablu.WebApiClient Works
  2. Download / Install
  3. Key Features
  4. Example
  5. Contributions
  6. Feedback

How Xablu.WebApiClient Works

WebApiClient is an open source library, created and maintained by Xablu. It is currently available for .NET / Xamarin. Through experience, we discovered that any .NET client app that has resilient calls to web services, uses a combination of libraries. Therefore, we built:

  • A REST client that is flexible and has no limitations.
  • A GraphQL client that is powerful and includes a query builder.

webapiclient model

Technical detail

We have taken the time to update this package with all kind of new features including different libraries. Including these libraries come with new technologies that you might not know about. Because of this reason we have made a summary below about each of the technologie explaining their use-case.

Refit:

Refit is the backbone for the REST client. It allows making HTTP/S requests to external services. Any app that uses Refit does not require much effort to start using our code. All the features provided by Refit are also exposed by our library without limitation.

Fussilade:

Fusillade is an HttpClient implementation which allows an app to efficiently schedule / create requests with different priorities. As a user you have the ability to set these priorities when you make a request.

Polly:

Polly is a very flexible resilience and transient-fault-handling library that allow apps to react to certain situations through policies like retry and timeout. This package provides a very simple way of using all common available features. Every HTTP call made has Polly implemented and the user has the option to customize this.

GraphQL.Client:

GraphQL.Client is the base of our GraphQL implementation, which also includes all additions from Fussilade and Polly as well. The coolest thing? We built a query builder that translates your common response models into a query (and it also gives you the results back as C# objects).

Download / Install

The Xablu.WebApiClient is written following the multi-target library approach. Meaning you can simply add the Xablu.WebApiClient package through NuGet. Install the NuGet package into your shared .NET Standard project and ALL Client projects.

  • NuGet: Xablu.WebApiClient
  • PM> Install-Package Xablu.WebApiClient
  • Namespace: using Xablu.WebApiClient

Key Features

The WebApiClient contains new features with respect to the previous version. The list of key features is depicted below:

REST Client:

  • Based on Refit ✔
  • Implemented Retry and Timeout from Polly ✔
  • Implemented Fusillade’s Priorities ✔

GraphQL Client:

  • Based on GraphQL.Client ✔
  • Implemented Retry and Timeout from Polly ✔
  • Implemented Fusillade’s Priorities ✔
  • Implemented a Custom, Object-Oriented Query Builder ✔

Example

Make sure to check out the Samples in this repository. Instructions on how to run the BooksQL sample app can be found here. Here is also an example call for connecting with a Web API service through Refit:

Abstract:

Task<TResult> Call<TResult>(Func<T, Task<TResult>> operation, Priority priority, int retryCount, Func<Exception, bool> shouldRetry, int timeout); 

Example implementation:

async Task<IEnumerable<MyModel>> GetModelsItemsAsync(bool forceRefresh = false) 
{
  IWebApiClient<IRefitInterface> webApiClient = WebApiClientFactory.Get<IRefitInterface>("baseURL", defaultHeaders: true);
  var jsonresult = await webApiClient.Call(
      operation: myRefitService => myRefitService.GetData(),
      priority: Priority.UserInitiated,
      retryCount: 2,
      shouldRetry: exception => myShouldRetryCondition(exception),
      timeout: 60); 
}

Down here is an example call for connecting with a web API service through GraphQL:

Abstract:

public static IWebApiClient<T> Get<T>(string baseUrl, bool autoRedirectRequests = true, Func<DelegatingHandler> delegatingHandler = default, IDictionary<string, string> defaultHeaders = default) where T : class

Implementation:

async Task GraphqlAsync()
{
  var defaultHeaders = new Dictionary<string, string>
  {
    ["User-Agent"] = "ExampleUser",
    ["Authorization"] = "Bearer ******"
  };
  IWebApiClient<IGitHubApi> webApiClient = WebApiClientFactory.Get<IGitHubApi>("https://api.github.com", false, default, defaultHeaders);
  var requestForSingleUser = new Request<UserResponseModel>("(login: \"ExampleUser\")");
  await webApiClient.SendQueryAsync(requestForSingleUser);
}

Contributions

All contributions are welcome! If you have a problem, please open an issue. And PRs are also appreciated!

Feedback

Are you using this library? We would love to hear from you! Or do you have any questions or suggestions? You are welcome to discuss it on:

  • Any 0.0
    • Fusillade (>= 0.7.0)
    • Newtonsoft.Json (>= 9.0.1)
    • Polly (>= 4.3.0)
  • Portable Class Library (.NETFramework 4.5, Windows 8.0, WindowsPhone 8.0): Profile78: 0.0.0.0

Owners

Xablu

Authors

Xablu

Project URL

https://github.com/Xablu/Xablu.WebApiClient

License

MIT

Tags

xamarin, monodroid, C#, xamarin.android, android, ios, uwp, Windows, tvOS, Mac, MacOS, Xablu, Web API, ASP.NET, .NET

Info

10 total downloads
0 downloads for version 0.10.0-unstable0003
Download (22.44 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
2.0.0.89-beta 132.39 KB Thu, 26 Mar 2020 21:08:47 GMT 0
2.0.0.80-beta 128.26 KB Tue, 24 Mar 2020 18:43:29 GMT 0
2.0.0.58-beta 391.81 KB Tue, 04 Feb 2020 13:44:10 GMT 0
2.0.0.49-beta 387.98 KB Mon, 03 Feb 2020 15:41:35 GMT 0
2.0.0.15-beta 363.96 KB Tue, 26 Nov 2019 15:53:53 GMT 0
2.0.0.8-beta 347.81 KB Mon, 25 Nov 2019 13:51:46 GMT 0
2.0.0.3-beta 339.73 KB Fri, 22 Nov 2019 19:32:11 GMT 0
2.0.0.2-beta 339.73 KB Fri, 22 Nov 2019 18:44:58 GMT 0
1.1.249 323.96 KB Mon, 18 Nov 2019 16:46:51 GMT 0
1.1.245 323.83 KB Fri, 15 Nov 2019 12:46:05 GMT 0
1.1.162 136 KB Fri, 23 Feb 2018 15:06:48 GMT 2
1.1.156 136.35 KB Tue, 13 Feb 2018 15:44:28 GMT 0
1.1.0 136.28 KB Tue, 13 Feb 2018 15:37:00 GMT 0
1.1.0-unstable0001 36.1 KB Fri, 10 Nov 2017 10:46:50 GMT 1
1.1.0-beta 139.75 KB Tue, 13 Feb 2018 15:31:02 GMT 0
0.15.0-unstable0052 36.16 KB Fri, 10 Nov 2017 10:31:54 GMT 0
0.15.0-unstable0001 48.09 KB Thu, 21 Sep 2017 08:48:04 GMT 0
0.14.0-unstable0008 48.15 KB Wed, 20 Sep 2017 14:48:59 GMT 0
0.14.0-unstable0005 47.75 KB Fri, 15 Sep 2017 08:44:16 GMT 0
0.14.0-unstable0004 47.74 KB Thu, 14 Sep 2017 14:15:49 GMT 0
0.14.0-unstable0003 47.77 KB Thu, 14 Sep 2017 13:58:16 GMT 0
0.13.0-unstable0009 47.99 KB Wed, 12 Jul 2017 10:52:38 GMT 0
0.12.0 34.14 KB Wed, 12 Jul 2017 00:16:23 GMT 3
0.11.0-unstable0029 34.13 KB Sun, 09 Jul 2017 13:29:16 GMT 4
0.11.0-unstable0027 33.24 KB Mon, 26 Jun 2017 21:32:57 GMT 0
0.11.0-unstable0023 33.35 KB Sun, 18 Jun 2017 20:22:31 GMT 0
0.11.0-unstable0022 33.39 KB Tue, 06 Jun 2017 12:59:59 GMT 0
0.11.0-unstable0020 33.33 KB Mon, 08 May 2017 11:47:55 GMT 0
0.11.0-unstable0014 33.32 KB Wed, 19 Apr 2017 11:43:11 GMT 0
0.10.0-unstable0005 22.43 KB Mon, 13 Feb 2017 08:46:58 GMT 0
0.10.0-unstable0004 22.45 KB Mon, 13 Feb 2017 08:40:01 GMT 0
0.10.0-unstable0003 22.44 KB Sun, 12 Feb 2017 18:24:21 GMT 0
0.10.0-unstable0001 21.66 KB Tue, 07 Feb 2017 09:18:30 GMT 0