blob: a30c7b38cd16df39d1c51f160b59aa6a7b9fa7ff (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
.. _akkahttp:
akka-http backend
=================
To use, add the following dependency to your project::
"com.softwaremill.sttp" %% "akka-http-backend" % "1.0.0"
This backend depends on `akka-http <http://doc.akka.io/docs/akka-http/current/scala/http/>`_. A fully **asynchronous** backend. Sending a request returns a response wrapped in a ``Future``.
Next you'll need to add an implicit value::
implicit val sttpBackend = AkkaHttpBackend()
// or, if you'd like to use an existing actor system:
implicit val sttpBackend = AkkaHttpBackend.usingActorSystem(actorSystem)
This backend supports sending and receiving `akka-streams <http://doc.akka.io/docs/akka/current/scala/stream/index.html>`_ streams of type ``akka.stream.scaladsl.Source[ByteString, Any]``.
To set the request body as a stream::
import com.softwaremill.sttp._
import com.softwaremill.sttp.akkahttp._
import akka.stream.scaladsl.Source
import akka.util.ByteString
val source: Source[ByteString, Any] = ...
sttp
.streamBody(source)
.post(uri"...")
To receive the response body as a stream::
import com.softwaremill.sttp._
import com.softwaremill.sttp.akkahttp._
import akka.stream.scaladsl.Source
import akka.util.ByteString
implicit val sttpBackend = AkkaHttpBackend()
val response: Future[Response[Source[ByteString, Any]]] =
sttp
.post(uri"...")
.response(asStream[Source[ByteString, Any]])
.send()
|