diff options
author | Omar Alejandro Mainegra Sarduy <omainegra@gmail.com> | 2017-08-11 17:45:29 -0400 |
---|---|---|
committer | Omar Alejandro Mainegra Sarduy <omainegra@gmail.com> | 2017-08-11 17:45:29 -0400 |
commit | ad28cb44c9a39b6bb5b7176358381b19b6e9ac28 (patch) | |
tree | 7a0a10f6270e3233633eda1e7f6b90ea4a12085d /README.md | |
parent | c6c1f5a34930946e8ab4e9248b9255ce2e1464fe (diff) | |
parent | 00e10184c05431d2692d2b54425481a67ee3bc8e (diff) | |
download | sttp-ad28cb44c9a39b6bb5b7176358381b19b6e9ac28.tar.gz sttp-ad28cb44c9a39b6bb5b7176358381b19b6e9ac28.tar.bz2 sttp-ad28cb44c9a39b6bb5b7176358381b19b6e9ac28.zip |
Merge branch 'master' into okhttp3-monix
# Conflicts:
# build.sbt
# okhttp-client-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 48 |
1 files changed, 40 insertions, 8 deletions
@@ -59,7 +59,7 @@ If you are an [Ammonite](http://ammonite.io) user, you can quickly start experimenting with sttp by copy-pasting the following: ```scala -import $ivy.`com.softwaremill.sttp::core:0.0.5` +import $ivy.`com.softwaremill.sttp::core:0.0.6` import com.softwaremill.sttp._ implicit val handler = HttpURLConnectionSttpHandler sttp.get(uri"http://httpbin.org/ip").send() @@ -70,7 +70,7 @@ sttp.get(uri"http://httpbin.org/ip").send() SBT dependency: ```scala -"com.softwaremill.sttp" %% "core" % "0.0.5" +"com.softwaremill.sttp" %% "core" % "0.0.6" ``` `sttp` is available for Scala 2.11 and 2.12, and requires Java 8. The core @@ -209,7 +209,7 @@ implicit val sttpHandler = HttpURLConnectionSttpHandler To use, add the following dependency to your project: ```scala -"com.softwaremill.sttp" %% "akka-http-handler" % "0.0.5" +"com.softwaremill.sttp" %% "akka-http-handler" % "0.0.6" ``` This handler depends on [akka-http](http://doc.akka.io/docs/akka-http/current/scala/http/). @@ -268,13 +268,13 @@ val response: Future[Response[Source[ByteString, Any]]] = To use, add the following dependency to your project: ```scala -"com.softwaremill.sttp" %% "async-http-client-handler-future" % "0.0.5" +"com.softwaremill.sttp" %% "async-http-client-handler-future" % "0.0.6" // or -"com.softwaremill.sttp" %% "async-http-client-handler-scalaz" % "0.0.5" +"com.softwaremill.sttp" %% "async-http-client-handler-scalaz" % "0.0.6" // or -"com.softwaremill.sttp" %% "async-http-client-handler-monix" % "0.0.5" +"com.softwaremill.sttp" %% "async-http-client-handler-monix" % "0.0.6" // or -"com.softwaremill.sttp" %% "async-http-client-handler-cats" % "0.0.5" +"com.softwaremill.sttp" %% "async-http-client-handler-cats" % "0.0.6" ``` This handler depends on [async-http-client](https://github.com/AsyncHttpClient/async-http-client). @@ -356,7 +356,7 @@ val response: Task[Response[Observable[ByteBuffer]]] = To use, add the following dependency to your project: ```scala -"com.softwaremill.sttp" %% "okhttp-client-handler" % "0.0.5" +"com.softwaremill.sttp" %% "okhttp-client-handler" % "0.0.6" ``` This handler depends on [OkHttp](http://square.github.io/okhttp/), and offers @@ -375,6 +375,38 @@ with a monad for the response wrapper. This brings the possibility to `map` and `flatMap` over responses. That way you could implement e.g. a logging or metric-capturing wrapper. +## JSON + +JSON encoding of bodies and decoding of responses can be handled using +[Circe](https://circe.github.io/circe/) by the `circe` module. To use +add the following dependency to your project: + +```scala +"com.softwaremill.sttp" %% "circe" % "0.0.6" +``` + +This module adds a method to the request and a function that can be given to +a request to decode the response to a specific object. + +```scala +import com.softwaremill.sttp._ +import com.softwaremill.sttp.circe._ + +implicit val handler = HttpURLConnectionSttpHandler + +// Assume that there is an implicit circe encoder in scope +// for the request Payload, and a decoder for the Response +val requestPayload: Payload = ??? + +val response: Either[io.circe.Error, Response] = + sttp + .post(uri"...") + .body(requestPayload) + .response(asJson[Response]) + .send() +``` + + ## Request type All request descriptions have type `RequestT[U, T, S]` (T as in Template). |