Tranquil HTTP is a C# HTTP library for Mobile Development aiming to make it really easy to solve complex HTTP communication scenarios.


Keywords
HTTPClient, HTTP, Fusillade, Opinionated, WebApi, REST, JSON
Install
Install-Package TranquilHTTP -Version 0.1.0.11

Documentation

Tranquil HTTP

Tranquil HTTP is a C# HTTP library for Mobile Development aiming to make it really easy to solve complex HTTP communication scenarios.

To accomplish this Tranquil HTTP wraps arround the excellent work of Paul Betts by incorporating two of his open-source libraries "ModernHttpClient" and "Fusillade".

The idea of Tranquil HTTP is heavily based on the article "Resilient network services with mobile Xamarin apps" by Rob Gibbens.

Installation

You can install Tranquil HTTP through NuGet. Simply run the following command in the Package Manager Console:

Install-Package TranquilHTTP

Example usage

To start using TranquilHTTP, simply create a new instance of the WebApiClient class. To make full use of the priority and rate limiting features of TranquilHTTP it is important you reuse the instance of the WebApiClient class for all HTTP requests send to the same base address. Common pratice would be to register the WebApiClient with a DI container as singleton. Below is a simple example showing how to make a simple GET request:

public class Echo 
{
    public string One { get; set; }
    public string Key { get; set; }
}

public class EchoService
{
  private readonly IWebApiClient _webApiClient;

  public EchoService(IWebApiClient webApiClient)
  {
    _webApiClient = webApiClient;
  }

  public async Task<Echo> GetEchoAsync()
  {
    var result = await _webApiClient.GetAsync<Echo>(
    Priority.UserInitiated,
    "key/value/one/two");

    if (result == null || !result.IsSuccessStatusCode)
    {
      // Do some error handling
    }

    return result.Content;
}