Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active September 16, 2020 16:59
Show Gist options
  • Save adamw/f79ebd35e0d1e9f95e021cb38c4d860d to your computer and use it in GitHub Desktop.
Save adamw/f79ebd35e0d1e9f95e021cb38c4d860d to your computer and use it in GitHub Desktop.
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