blob: 086fa609d7d0210a3996c2741e741681a9a366b9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
.. _json:
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::
"com.softwaremill.sttp" %% "circe" % "0.0.20"
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::
import com.softwaremill.sttp._
import com.softwaremill.sttp.circe._
implicit val backend = HttpURLConnectionBackend()
// 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()
|