aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorBjørn Madsen <bm@aeons.dk>2017-08-07 09:34:30 +0200
committerBjørn Madsen <bm@aeons.dk>2017-08-07 09:34:40 +0200
commit461ed700256e33aea7fb7b033e23698e8239fd09 (patch)
tree776bccaedfa42172e0d4fc86c9af7f30a5260af2 /README.md
parentccd84dadf7e7b1b5c037933f3a2ae56272c62919 (diff)
downloadsttp-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.md32
1 files changed, 32 insertions, 0 deletions
diff --git a/README.md b/README.md
index 1bc88dd..084d27d 100644
--- a/README.md
+++ b/README.md
@@ -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).