Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active September 16, 2020 16:59
Show Gist options
  • Save adamw/91c670fde8e898646a25d1011183b808 to your computer and use it in GitHub Desktop.
Save adamw/91c670fde8e898646a25d1011183b808 to your computer and use it in GitHub Desktop.
package sttp.client3.examples
import io.circe
import io.circe.generic.auto._
import sttp.client3._
import sttp.client3.circe._
object GetRawRequestBodySynchronous extends App {
case class HttpBinResponse(origin: String, headers: Map[String, String])
val request = basicRequest
.get(uri"https://httpbin.org/get")
.response(asBoth(asJson[HttpBinResponse], asStringAlways))
val backend: SttpBackend[Identity, Any] = HttpURLConnectionBackend()
try {
val response: Response[(Either[ResponseException[String, circe.Error], HttpBinResponse], String)] =
request.send(backend)
val (parsed, raw) = response.body
println("Got response - parsed: " + parsed)
println("Got response - raw: " + raw)
} finally backend.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment