Async HTTP Client and Akka

UPDATE: I just discovered Spray, an asynchronous REST library. It also has a nice HTTP client and is fully integrated to Akka. So I would recommend to to used that and ignore this post. For regular Java the Async HTTP Client is still a great choise

HTTP requests (and network requests in general) are extremely slow compared to other operations. So they can introduce a lot of latency in your system when you application is waiting for the response. This especially adds up when you fetch stuff from multiple servers. Therefore you often want to do such an operation asynchronously instead of blocking and waiting.

HTTP over tincan-phones, hmm, why not IETF?

HTTP over tincan-phones, hmm, why not IETF?

The wonderful Async Http Client provides exactly this. It makes it very easy to do asynchronous HTTP and HTTPS requests. The API is easy to use and let’s you do what you need. I recommend it.

Async HTTP in Akka

For the asynchronous world of Akka the Async HTTP API is a good fit. For some more convenience I wrapped the main API so that it integrates a little better with Akka. Mainly the execute operations now returns an Akka future. And the client is a simple Akka extension. So you can do a simple request like this:

Otherwise API is more or less the same or exactly the same as in raw library.


The wrapper also reads the configuration from the regular Akka configuration of the given Actor system. For example when you want to enable redirects:

Here’s the default reference configuration:

Get The Stuff

The tiny ‘wrapper’ is on my github repo here: Also the stuff is on my github hosted Maven Snapshot repository. You can grab it via SBT or Maven:

Repository for Maven:
GroupID: info.gamlor.akkaasync
ArtifactID: akka-webclient_2.9.1
Version: 1.0-SNAPSHOT

So via SBT:

That’s it.

Improvements will follow when I see a need. Or just use the raw Async HTTP library.

Tagged on: ,