Last active
September 16, 2020 16:59
-
-
Save adamw/f79ebd35e0d1e9f95e021cb38c4d860d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sttp.client3.examples | |
import io.circe.generic.auto._ | |
import sttp.client3._ | |
import sttp.client3.asynchttpclient.monix.AsyncHttpClientMonixBackend | |
import sttp.client3.circe._ | |
object GetAndParseJsonGetRightMonixCirce extends App { | |
import monix.execution.Scheduler.Implicits.global | |
case class HttpBinResponse(origin: String, headers: Map[String, String]) | |
val request: Request[HttpBinResponse, Any] = basicRequest | |
.get(uri"https://httpbin.org/get") | |
.response(asJson[HttpBinResponse].getRight) | |
AsyncHttpClientMonixBackend | |
.resource() | |
.use { backend => | |
request.send(backend).map { response: Response[HttpBinResponse] => | |
println(s"Got response code: ${response.code}") | |
println(response.body) | |
} | |
} | |
.runSyncUnsafe() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment