diff options
author | Bjørn Madsen <bm@aeons.dk> | 2017-08-07 09:34:30 +0200 |
---|---|---|
committer | Bjørn Madsen <bm@aeons.dk> | 2017-08-07 09:34:40 +0200 |
commit | 461ed700256e33aea7fb7b033e23698e8239fd09 (patch) | |
tree | 776bccaedfa42172e0d4fc86c9af7f30a5260af2 /README.md | |
parent | ccd84dadf7e7b1b5c037933f3a2ae56272c62919 (diff) | |
download | sttp-461ed700256e33aea7fb7b033e23698e8239fd09.tar.gz sttp-461ed700256e33aea7fb7b033e23698e8239fd09.tar.bz2 sttp-461ed700256e33aea7fb7b033e23698e8239fd09.zip |
Add some documentation for the circe module
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"...") + .jsonBody(requestPayload) + .response(asJson[Response]) + .send() +``` + + ## Request type All request descriptions have type `RequestT[U, T, S]` (T as in Template). |