Fast HTTP with ModernHttpClient

Published on October 04, 2013

Today, I open-sourced a drop-dead simple way to make your code using HttpClient run way faster on Android and iOS, called ModernHttpClient.

Using this library is basically the easiest thing in the world, just replace every time you wrote new HttpClient(), with:

var httpClient = new HttpClient(new AFNetworkHandler());

or on Android:

var httpClient = new HttpClient(new OkHttpNetworkHandler());

Some Motivation

The default HttpClient implementation on Xamarin platforms is slow. Real slow. And blocking. Spin up enough concurrent network connections, and you’re in for a bad time. What to do? Using HTTP is a huge part of almost every mobile application, and it needs to be super fast. On iOS, Xamarin has provided CFNetworkHandler, but at least in my app, I’ve experienced a lot of “Make a request, it hangs” bugs when I started making concurrent requests.

If you were writing a platform-specific mobile app, you’d use one of two libraries: on iOS, you’d probably use AFNetworking, and on Android, a great library to use is Square’s OkHttp. Both of these libraries are designed around writing great mobile applications.

However, the disadvantage to using these libraries directly is that you have to basically make all of your networking code platform-specific. That sucks. So, I wrote an implementation of the standard .NET HttpClient that uses both of these libraries, ModernHttpClient.

This means, that you can code your HTTP code in a platform-independent way, but under the hood they are using the super awesome 3rd-party platform libraries which means they’re super fast, for free.


Anaïs Betts

Written by Anaïs [a.na'is] Betts, who lives in Berlin.

Twitter LogoCopyright 2018 Anaïs BettsGitHub Logo