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.
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: https://github.com/gamlerhart/akka-async-apis. Also the stuff is on my github hosted Maven Snapshot repository. You can grab it via SBT or Maven:
Repository for Maven: https://github.com/gamlerhart/gamlor-mvn/raw/master/snapshots
So via SBT:
Improvements will follow when I see a need. Or just use the raw Async HTTP library.
- 매시업 만드는 사람 좋아해요 / Mashup Creators Which I Like: Dan Mei, DJ Schmolli, Mashup Germany
- freeqnet’s Mixtape wichteln / freeqnet’s Mixtape Secret Santa / freeqnet의 비밀 선물 믹스테이프를 보내기