diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -374,6 +374,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.5" +``` + +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). |