https://github.com/fullfacing/akkamonixsttpbackend
A STTP backend that utilizes Monix Observables and Tasks.
https://github.com/fullfacing/akkamonixsttpbackend
akka-http monix streaming sttp
Last synced: 9 months ago
JSON representation
A STTP backend that utilizes Monix Observables and Tasks.
- Host: GitHub
- URL: https://github.com/fullfacing/akkamonixsttpbackend
- Owner: fullfacing
- License: mit
- Created: 2019-07-09T11:38:11.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2024-07-29T15:22:25.000Z (over 1 year ago)
- Last Synced: 2025-03-25T22:35:40.091Z (10 months ago)
- Topics: akka-http, monix, streaming, sttp
- Language: Scala
- Size: 197 KB
- Stars: 14
- Watchers: 2
- Forks: 2
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://circleci.com/gh/fullfacing/akkaMonixSttpBackend)
[](https://search.maven.org/search?q=a:sttp-akka-monix-task_2.13)
[](https://scala-steward.org)
# akkaMonixSttpBackend
**Introduction:**
akkaMonixSttpBackend is a backend for [sttp](https://sttp.readthedocs.io/en/latest/index.html) using [Akka-HTTP](https://doc.akka.io/docs/akka-http/current/index.html) to handle requests, and with [Task](https://monix.io/docs/3x/eval/task.html) as the response Monad and [Observable](https://monix.io/docs/3x/reactive/observable.html) as the streaming type. It is a modification of the [Akka-HTTP backend](https://sttp.readthedocs.io/en/latest/backends/akkahttp.html) provided by sttp, with instances of Futures deferred to Tasks and Akka-Streams Sources converted to Observables.
The motivation behind creating this backend as opposed to using the existing [Monix wrapped async-http-client backend](https://sttp.readthedocs.io/en/latest/backends/asynchttpclient.html) is to give an alternative for projects that already have Akka-HTTP as a dependency, removing the need for the async-http-client dependency as well.
**Installation:**
Add the following sbt dependency:
`"com.fullfacing" %% "sttp-akka-monix-task" % "1.5.0"`
**Usage:**
Usage is identical to the [Akka-HTTP backend](https://sttp.readthedocs.io/en/latest/backends/akkahttp.html) with only the response type differing:
```scala
import akka.util.ByteString
import com.fullfacing.akka.monix.task.backend.AkkaMonixHttpBackend
import sttp.client.{Response, SttpBackend, _}
import monix.eval.Task
import monix.reactive.Observable
implicit val backend: SttpBackend[Task, Observable[ByteString], NothingT] = AkkaMonixHttpBackend()
// To set the request body as a stream:
val observable: Observable[ByteString] = ???
sttp
.streamBody(observable)
.post(uri"...")
.send()
// To receive the response body as a stream:
val response: Task[Response[Observable[ByteString]]] =
sttp
.post(uri"...")
.response(asStream[Observable[ByteString]])
.send()
```