diff options
author | adamw <adam@warski.org> | 2017-10-12 19:23:09 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-10-12 19:23:09 +0200 |
commit | 7bf4d02da823c21b27cf20ba0b764b511ac69432 (patch) | |
tree | 04b9ab557c4af82b9970af386e6f4f9e4292e472 /docs/json.rst | |
parent | 7885188a982c193e26f8ca6bc9aea8f6a642b32d (diff) | |
download | sttp-7bf4d02da823c21b27cf20ba0b764b511ac69432.tar.gz sttp-7bf4d02da823c21b27cf20ba0b764b511ac69432.tar.bz2 sttp-7bf4d02da823c21b27cf20ba0b764b511ac69432.zip |
More docs
Diffstat (limited to 'docs/json.rst')
-rw-r--r-- | docs/json.rst | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/json.rst b/docs/json.rst new file mode 100644 index 0000000..28cee81 --- /dev/null +++ b/docs/json.rst @@ -0,0 +1,29 @@ +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() + + |