RequestT

sttp.client3.RequestT
See theRequestT companion object
case class RequestT[U[_], T, -R](method: U[Method], uri: U[Uri], body: RequestBody[R], headers: Seq[Header], response: ResponseAs[T, R], options: RequestOptions, tags: Map[String, Any]) extends HasHeaders with RequestTExtensions[U, T, R]

Describes a HTTP request, along with a description of how the response body should be handled.

The request can be sent:

  • synchronously, using SimpleHttpClient.send
  • using the send methods, which support any effect. The backend must provide a superset of the capabilities required by the request.

Attributes

R

The backend capabilities required by the request or response description. This might be Any (no requirements), Effect (the backend must support the given effect type), Streams (the ability to send and receive streaming bodies) or sttp.capabilities.WebSockets (the ability to handle websocket requests).

T

The target type, to which the response body should be read.

U

Specifies if the method & uri are specified. By default can be either: * Empty, which is a type constructor which always resolves to None. This type of request is aliased to PartialRequest: there's no method and uri specified, and the request cannot be sent. * Identity, which is an identity type constructor. This type of request is aliased to Request: the method and uri are specified, and the request can be sent.

response

Description of how the response body should be handled. Needs to be specified upfront so that the response is always consumed and hence there are no requirements on client code to consume it. An exception to this are unsafe streaming and websocket responses, which need to be consumed/closed by the client.

tags

Request-specific tags which can be used by backends for logging, metrics, etc. Not used by default.

Companion:
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait RequestTExtensions[U, T, R]
trait HasHeaders
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

def acceptEncoding(encoding: String): RequestT[U, T, R]
def auth: SpecifyAuthScheme[U, T, R]
def body(b: String): RequestT[U, T, R]

Uses the utf-8 encoding.

Uses the utf-8 encoding.

If content type is not yet specified, will be set to text/plain with utf-8 encoding.

If content length is not yet specified, will be set to the number of bytes in the string using the utf-8 encoding.

Attributes

def body(b: String, encoding: String): RequestT[U, T, R]

If content type is not yet specified, will be set to text/plain with the given encoding.

If content type is not yet specified, will be set to text/plain with the given encoding.

If content length is not yet specified, will be set to the number of bytes in the string using the given encoding.

Attributes

def body(b: Array[Byte]): RequestT[U, T, R]

If content type is not yet specified, will be set to application/octet-stream.

If content type is not yet specified, will be set to application/octet-stream.

If content length is not yet specified, will be set to the length of the given array.

Attributes

def body(b: ByteBuffer): RequestT[U, T, R]

If content type is not yet specified, will be set to application/octet-stream.

If content type is not yet specified, will be set to application/octet-stream.

Attributes

def body(b: InputStream): RequestT[U, T, R]

If content type is not yet specified, will be set to application/octet-stream.

If content type is not yet specified, will be set to application/octet-stream.

Attributes

def body(fs: Map[String, String]): RequestT[U, T, R]

Encodes the given parameters as form data using utf-8. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

Encodes the given parameters as form data using utf-8. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

If content length is not yet specified, will be set to the length of the number of bytes in the url-encoded parameter string.

Attributes

def body(fs: Map[String, String], encoding: String): RequestT[U, T, R]

Encodes the given parameters as form data. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

Encodes the given parameters as form data. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

If content length is not yet specified, will be set to the length of the number of bytes in the url-encoded parameter string.

Attributes

def body(fs: (String, String)*): RequestT[U, T, R]

Encodes the given parameters as form data using utf-8. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

Encodes the given parameters as form data using utf-8. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

If content length is not yet specified, will be set to the length of the number of bytes in the url-encoded parameter string.

Attributes

def body(fs: Seq[(String, String)], encoding: String): RequestT[U, T, R]

Encodes the given parameters as form data. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

Encodes the given parameters as form data. If content type is not yet specified, will be set to application/x-www-form-urlencoded.

If content length is not yet specified, will be set to the length of the number of bytes in the url-encoded parameter string.

Attributes

def contentLength(l: Long): RequestT[U, T, R]
def contentType(ct: String): RequestT[U, T, R]
def contentType(mt: MediaType): RequestT[U, T, R]
def contentType(ct: String, encoding: String): RequestT[U, T, R]
def cookies(r: Response[_]): RequestT[U, T, R]
def cookies(cs: Iterable[CookieWithMeta]): RequestT[U, T, R]
def cookies(nvs: (String, String)*): RequestT[U, T, R]
def delete(uri: Uri): Request[T, R]
def followRedirects(fr: Boolean): RequestT[U, T, R]
def get(uri: Uri): Request[T, R]
def head(uri: Uri): Request[T, R]
def header(h: Header, replaceExisting: Boolean): RequestT[U, T, R]

Adds the given header to the end of the headers sequence.

Adds the given header to the end of the headers sequence.

Attributes

replaceExisting

If there's already a header with the same name, should it be replaced?

def header(k: String, v: String, replaceExisting: Boolean): RequestT[U, T, R]

Adds the given header to the end of the headers sequence.

Adds the given header to the end of the headers sequence.

Attributes

replaceExisting

If there's already a header with the same name, should it be replaced?

def header(k: String, v: String): RequestT[U, T, R]

Adds the given header to the end of the headers sequence.

Adds the given header to the end of the headers sequence.

Attributes

def header(k: String, ov: Option[String]): RequestT[U, T, R]

Adds the given header to the end of the headers sequence, if the value is defined. Otherwise has no effect.

Adds the given header to the end of the headers sequence, if the value is defined. Otherwise has no effect.

Attributes

def headers(hs: Map[String, String]): RequestT[U, T, R]

Adds the given headers to the end of the headers sequence.

Adds the given headers to the end of the headers sequence.

Attributes

def headers(hs: Map[String, String], replaceExisting: Boolean): RequestT[U, T, R]

Adds the given headers to the end of the headers sequence.

Adds the given headers to the end of the headers sequence.

Attributes

replaceExisting

If there's already a header with the same name, should it be replaced?

def headers(hs: Header*): RequestT[U, T, R]

Adds the given headers to the end of the headers sequence.

Adds the given headers to the end of the headers sequence.

Attributes

def headers(hs: Seq[Header], replaceExisting: Boolean): RequestT[U, T, R]

Adds the given headers to the end of the headers sequence.

Adds the given headers to the end of the headers sequence.

Attributes

def httpVersion(version: HttpVersion): RequestT[U, T, R]

Allows setting HTTP version per request. Supported only is a few backends

Allows setting HTTP version per request. Supported only is a few backends

Attributes

version:

one of values from HttpVersion enum.

Returns:

request with version tag

def httpVersion: Option[HttpVersion]

GetHttpVersion from tags in request. Supported only is a few backends

GetHttpVersion from tags in request. Supported only is a few backends

Attributes

Returns:

one of values form HttpVersion enum or None

def isWebSocket: Boolean
def logSettings(logRequestBody: Option[Boolean], logResponseBody: Option[Boolean], logRequestHeaders: Option[Boolean], logResponseHeaders: Option[Boolean]): RequestT[U, T, R]

Will only have effect when using the LoggingBackend

Will only have effect when using the LoggingBackend

Attributes

def mapResponse[T2](f: T => T2): RequestT[U, T2, R]
def mapResponseRight[B2](f: B => B2): RequestT[U, Either[A, B2], R]
Implicitly added by RichRequestTEither
def maxRedirects(n: Int): RequestT[U, T, R]
def method(method: Method, uri: Uri): Request[T, R]
def multipartBody[R2](ps: Seq[Part[RequestBody[R2]]]): RequestT[U, T, R & R2]
def multipartBody[R2](p1: Part[RequestBody[R2]], ps: Part[RequestBody[R2]]*): RequestT[U, T, R & R2]
def options(uri: Uri): Request[T, R]
def patch(uri: Uri): Request[T, R]
def post(uri: Uri): Request[T, R]
def put(uri: Uri): Request[T, R]
def readTimeout(t: Duration): RequestT[U, T, R]

When the request is sent, if reading the response times out (there's no activity for the given period of time), a failed effect will be returned, or an exception will be thrown

When the request is sent, if reading the response times out (there's no activity for the given period of time), a failed effect will be returned, or an exception will be thrown

Attributes

def redirectToGet(r: Boolean): RequestT[U, T, R]

When a POST or PUT request is redirected, should the redirect be a POST/PUT as well (with the original body), or should the request be converted to a GET without a body.

When a POST or PUT request is redirected, should the redirect be a POST/PUT as well (with the original body), or should the request be converted to a GET without a body.

Note that this only affects 301 and 302 redirects. 303 redirects are always converted, while 307 and 308 redirects always keep the same method.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections for details.

Attributes

def response[T2, R2](ra: ResponseAs[T2, R2]): RequestT[U, T2, R & R2]

Specifies the target type to which the response body should be read. Note that this replaces any previous specifications, which also includes any previous mapResponse invocations.

Specifies the target type to which the response body should be read. Note that this replaces any previous specifications, which also includes any previous mapResponse invocations.

Attributes

def responseGetEither: RequestT[U, Either[HE, B], R]
Implicitly added by RichRequestTEither
def send[F[_], P](backend: SttpBackend[F, P])(implicit isIdInRequest: IsIdInRequest[U], pEffectFIsR: P & Effect[F] <:< R): F[Response[T]]

Sends the request, using the given backend. Only requests for which the method & URI are specified can be sent.

Sends the request, using the given backend. Only requests for which the method & URI are specified can be sent.

The required capabilities must be a subset of the capabilities provided by the backend.

Attributes

Returns:

For synchronous backends (when the effect type is Identity), Response is returned directly and exceptions are thrown. For asynchronous backends (when the effect type is e.g. scala.concurrent.Future), an effect containing the Response is returned. Exceptions are represented as failed effects (e.g. failed futures). The response body is deserialized as specified by this request (see RequestT.response). Known exceptions are converted by backends to one of SttpClientException. Other exceptions are thrown unchanged.

def show(includeBody: Boolean, includeHeaders: Boolean, sensitiveHeaders: Set[String]): String
def showBasic: String
def streamBody[S](s: Streams[S])(b: BinaryStream): RequestT[U, T, R & S]
def tag(k: String, v: Any): RequestT[U, T, R]
def tag(k: String): Option[Any]
def toCurl(implicit isIdInRequest: IsIdInRequest[U]): String
def toCurl(sensitiveHeaders: Set[String])(implicit isIdInRequest: IsIdInRequest[U]): String
def toRfc2616Format(implicit isIdInRequest: IsIdInRequest[U]): String
def toRfc2616Format(sensitiveHeaders: Set[String])(implicit isIdInRequest: IsIdInRequest[U]): String

Deprecated methods

def send[F[_], P]()(implicit backend: SttpBackend[F, P], pEffectFIsR: P & Effect[F] <:< R, isIdInRequest: IsIdInRequest[U]): F[Response[T]]

Sends the request, using the backend from the implicit scope. Only requests for which the method & URI are specified can be sent.

Sends the request, using the backend from the implicit scope. Only requests for which the method & URI are specified can be sent.

The required capabilities must be a subset of the capabilities provided by the backend.

Attributes

Returns:

For synchronous backends (when the effect type is Identity), Response is returned directly and exceptions are thrown. For asynchronous backends (when the effect type is e.g. scala.concurrent.Future), an effect containing the Response is returned. Exceptions are represented as failed effects (e.g. failed futures). The response body is deserialized as specified by this request (see RequestT.response). Known exceptions are converted by backends to one of SttpClientException. Other exceptions are thrown unchanged.

Deprecated
[Since version 3.0.0] use request.send(backend), providing the backend explicitly

Inherited methods

def body[B : BodySerializer](b: B): RequestT[U, T, R]

If content type is not yet specified, will be set to application/octet-stream.

If content type is not yet specified, will be set to application/octet-stream.

Attributes

Inherited from:
RequestTExtensions
def body(path: Path): RequestT[U, T, R]

If content type is not yet specified, will be set to application/octet-stream.

If content type is not yet specified, will be set to application/octet-stream.

If content length is not yet specified, will be set to the length of the given file.

Attributes

Inherited from:
RequestTExtensions
def body(file: File): RequestT[U, T, R]

If content type is not yet specified, will be set to application/octet-stream.

If content type is not yet specified, will be set to application/octet-stream.

If content length is not yet specified, will be set to the length of the given file.

Attributes

Inherited from:
RequestTExtensions
def contentLength: Option[Long]

Attributes

Inherited from:
HasHeaders
def contentType: Option[String]

Attributes

Inherited from:
HasHeaders
def cookies: Seq[Either[String, CookieWithMeta]]

Attributes

Inherited from:
HasHeaders
def header(h: String): Option[String]

Attributes

Inherited from:
HasHeaders
def headers(h: String): Seq[String]

Attributes

Inherited from:
HasHeaders
def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product
def unsafeCookies: Seq[CookieWithMeta]

Attributes

Inherited from:
HasHeaders