I need a mature HTTP client library that is idiomatic to scala, concise in usage, simple semantics. I looked at the Apache HTTP and the Scala Dispatch and numerous new libraries that promise an idiomatic Scala wrapping. Apache HTTP client sure demands verbosity, while Dispatch was easily confusing.
What is a suitable HTTP client for Scala usage?
ScalaJ-Http is a very simple synchronous http client
https://github.com/scalaj/scalaj-http
I'd recommend it if you need a no-ceremony barebones Scala client.
Besides Dispatch there is not much out there. scalaz had a attempt at building a functional http client. But it is outdated for a while an no version of it exists in the scalaz7 branch. Additionally there is a useful wrapper of the ning async-http-client within the playframework. There your can do calls like:
You can use this API as inspiration if you don't use play! in your project and dislike the Dispatch API.
Spray
You really should consider using Spray. In my opinion it has a bit of tricky syntax, but it is still pretty usable if you aim to build a high-performance http client. The main advantage of using Spray is that it is based on the akka actor library, which is extremely scalable and powerful. You can scale out your http client to several machines by only changing
conf
files.Moreover few month ago Spray join Typesafe, and as I understand it will become a part of the basic akka distribution. proof
Play2
Another option is the Play2 WS lib usage (doc). As far as I know it is still not separated from the Play distribution, but due to its extremely simplicity it is worth it to spend some time attaching the whole Play framework to get that part. There are some issues with providing configuration to it, so this is not great for drop-and-use cases. However, we have used it in few non Play-based projects and everything was fine.
TwoSix years after originally responding to this post, I would have a different answer.I've been using akka-http, a collaboration between the spray and akka teams. It's backed by Lightbend, tightly aligned with the akka async environment... it's the right tool for this job.
Surprised that no one mentioned finagle here. It is super simple to use:
See quick start guid for more detail: https://twitter.github.io/finagle/guide/Quickstart.html
Having had some unhappy experiences with the Apache client, I set about writing my own. The built-in HttpURLConnection is widely asserted to be buggy. But that's not my experience of it. In fact, the reverse has been so, the Apache client having a somewhat problematic threading model. Since Java6 (or 5?), HttpURLConnection has provided efficient HTTP1.1 connections with essentials like keep-alive being built in, and it handles concurrent usage without fuss.
So, to compensate for the inconvenient API offered by HttpURLConnection, I set about writing a new API in Scala, as an open-source project. It's just a wrapper for HttpURLConnection, but unlike HttpURLConnection, it aims to be easy to use. Unlike Apache client, it should fit easily into an existing project. Unlike Dispatch, it should be easy to learn.
It's called Bee Client
My apologies for the shameless plug. :)