This project provides a fast, asynchronous & and non-blocking http client API.
It encapsulate, in Scala 2.10 API, the project async-http-client
This works in a Java 6+ environment
The project is available in 0.2-SNAPSHOT version !
The actual project release version is 0.1
- simple GET request OK (0.1)
- simple POST request OK (0.1)
- async api OK (0.1)
- HEAD, PUT, DELETE request OK (0.1)
- fluent API TODO
- sync api TODO
- proxy handling TODO
- Akka actor plugin api TODO
- other HTTP verb TODO
- WebSocket TODO
- SSL TODO
- Response streaming TODO
simplyscala-server is a SBT project.
It use 0.12 sbt version.
<dependency>
<groupId>com.github.simplyscala</groupId>
<artifactId>http-client_2.10</artifactId>
<version>0.1</version>
</dependency>
libraryDependencies += "com.github.simplyscala" %% "http-client" % "0.1"
In your play! project Build file :
object ApplicationBuild extends Build {
val appDependencies = Seq (
"com.github.simplyscala" %% "http-client" % "0.1"
)
}
You could be tempted to try SNAPSHOT version to test project’s next features.
<project ...>
<repositories>
<repository>
<id>maven snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
...
<dependency>
<groupId>com.github.simplyscala</groupId>
<artifactId>http-client_2.10</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
libraryDependencies += "com.github.simplyscala" %% "http-client" % "0.2-SNAPSHOT"
val response: Future[Response] = new AsyncHttpClient().get("http://someUrl/path?param1=value1;param2=value2")
val response: Future[Response] = new AsyncHttpClient().post("http://someUrl/path", Map("param" -> "value")
The AsyncHttpClient return asynchronous response. With Scala language, we use Future
api.
When we perform, for example, GET request :
val response: Future[Response] = new AsyncHttpClient().get("http://github.com/simplyscala/http-client")
We are two major ways to use this result :
// link to Future SIP & ScalaDoc
If we use asynchronous api to perform HTTP request, it is not recommended to block the result. But sometimes, we must :D
import scala.concurrent.duration._
...
val futureResponse: Future[Response] = new AsyncHttpClient().get("http://github.com/simplyscala/http-client")
val response = Await.result(futureResponse, 1 second)