sttp Documentation, Release 3
4.17.1 Basic response specifications
To conveniently specify how to deserialize the response body, a number of as(...Type...) methods are available.
They can be used to provide a value for the request description’s response property:
import sttp.client3._
basicRequest.response(asByteArray)
When the above request is completely described and sent, it will result in a Response[Either[String,
Array[Byte]]] (where the left and right correspond to non-2xx and 2xx status codes, as above).
Other possible response descriptions include (the first type parameter of ResponseAs specifies the type returned as
the response body, the second - the capabilities that the backend is required to support to send the request; Any means
no special requirements):
import sttp.client3._
import java.io.File
import java.nio.file.Path
def ignore: ResponseAs[Unit, Any] = ???
def asString: ResponseAs[Either[String, String], Any] = ???
def asStringAlways: ResponseAs[String, Any] = ???
def asString(encoding: String): ResponseAs[Either[String, String], Any] = ???
def asStringAlways(encoding: String): ResponseAs[String, Any] = ???
def asByteArray: ResponseAs[Either[String, Array[Byte]], Any] = ???
def asByteArrayAlways: ResponseAs[Array[Byte], Any] = ???
def asParams: ResponseAs[Either[String, Seq[(String, String)]], Any] = ???
def asParamsAlways: ResponseAs[Seq[(String, String)], Any] = ???
def asParams(encoding: String): ResponseAs[Either[String, Seq[(String, String)]],
˓→Any] = ???
def asParamsAlways(encoding: String): ResponseAs[Seq[(String, String)], Any] = ???
def asFile(file: File): ResponseAs[Either[String, File], Any] = ???
def asFileAlways(file: File): ResponseAs[File, Any] = ???
def asPath(path: Path): ResponseAs[Either[String, Path], Any] = ???
def asPathAlways(path: Path): ResponseAs[Path, Any] = ???
def asEither[A, B, R](onError: ResponseAs[A, R],
onSuccess: ResponseAs[B, R]): ResponseAs[Either[A, B], R] = ???
def fromMetadata[T, R](default: ResponseAs[T, R],
conditions: ConditionalResponseAs[T, R]
*
): ResponseAs[T, R] = ?
˓→??
def asBoth[A, B](l: ResponseAs[A, Any], r: ResponseAs[B, Any]): ResponseAs[(A, B),
˓→Any] = ???
def asBothOption[A, B, R](l: ResponseAs[A, R], r: ResponseAs[B, Any]): ResponseAs[(A,
˓→Option[B]), R] = ???
Hence, to discard the response body, the request description should include the following:
import sttp.client3._
basicRequest.response(ignore)
And to save the response to a file:
import sttp.client3._
import java.io._
(continues on next page)
4.17. Response body specification 39