Request

sttp.client4.Request
See theRequest companion object
case class Request[T](method: Method, uri: Uri, body: BasicBody, headers: Seq[Header], response: ResponseAs[T], options: RequestOptions, tags: Map[String, Any]) extends GenericRequest[T, Any], RequestBuilder[Request[T]]

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

The request can be sent using an instance of SyncBackend or Backend with the send method.

Type parameters

T

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

Value parameters

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.

tags

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

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait GenericRequest[T, Any]
trait RequestMetadata
trait HasHeaders
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def mapResponse[T2](f: T => T2): Request[T2]
def mapResponseRight[B2](f: B => B2): Request[Either[A, B2]]
Implicitly added by RichRequestTEither
override def method(method: Method, uri: Uri): Request[T]

Set the method & uri to the given ones.

Set the method & uri to the given ones.

Attributes

Definition Classes
def multipartStreamBody[S](ps: Seq[Part[BodyPart[S]]]): StreamRequest[T, S]
def multipartStreamBody[S](p1: Part[BodyPart[S]], ps: Part[BodyPart[S]]*): StreamRequest[T, S]
def response[T2](ra: ResponseAs[T2]): Request[T2]

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 response[F[_], T2](ra: WebSocketResponseAs[F, T2]): WebSocketRequest[F, T2]

Specifies that this is a WebSocket request. A WebSocketBackend will be required to send this request.

Specifies that this is a WebSocket request. A WebSocketBackend will be required to send this request.

Attributes

def response[T2, S](ra: StreamResponseAs[T2, S]): StreamRequest[T2, S]

Specifies that the response body should be processed using a non-blocking, asynchronous stream, as witnessed by the S capability. A StreamBackend will be required to send this request.

Specifies that the response body should be processed using a non-blocking, asynchronous stream, as witnessed by the S capability. A StreamBackend will be required to send this request.

Attributes

def response[T2, S](ra: WebSocketStreamResponseAs[T2, S]): WebSocketStreamRequest[T2, S]

Specifies that this is a WebSocket request, and the WebSocket will be processed using a non-blocking, asynchronous stream, as witnessed by the S capability. A WebSocketStreamBackend will be required to send this request.

Specifies that this is a WebSocket request, and the WebSocket will be processed using a non-blocking, asynchronous stream, as witnessed by the S capability. A WebSocketStreamBackend will be required to send this request.

Attributes

def responseGetEither: Request[Either[HE, B]]
Implicitly added by RichRequestTEither
def send[F[_]](backend: Backend[F]): F[Response[T]]

Sends the request, using the given backend.

Sends the request, using the given backend.

Attributes

Returns

An F-effect, containing a Response, with the body handled as specified by this request (see Request.response). Effects might include asynchronous computations (e.g. scala.concurrent.Future), pure effect descriptions (IO), or error wrappers (e.g. TryBackend). Exceptions are represented as failed effects (e.g. failed futures). The response body is deserialized as specified by this request (see Request.response). Known exceptions are converted by backends to one of SttpClientException. Other exceptions are thrown unchanged.

def send(backend: SyncBackend): Response[T]

Sends the request synchronously, using the given backend.

Sends the request synchronously, using the given backend.

Attributes

Returns

A Response, with the body handled as specified by this request (see Request.response). The response body is deserialized as specified by this request (see Request.response). Known exceptions are converted by backends to one of SttpClientException. Other exceptions are thrown unchanged.

override def showBasic: String

Attributes

Definition Classes
def streamBody[S](s: Streams[S])(b: s.BinaryStream): StreamRequest[T, S]
override def withHeaders(headers: Seq[Header]): Request[T]

Replace all headers with the given ones.

Replace all headers with the given ones.

Attributes

Definition Classes
override def withOptions(options: RequestOptions): Request[T]

Replace all options with the given ones.

Replace all options with the given ones.

Attributes

Definition Classes
override def withTags(tags: Map[String, Any]): Request[T]

Replace all tags with the given ones.

Replace all tags with the given ones.

Attributes

Definition Classes

Inherited methods

def acceptEncoding(encoding: String): Request[T]

Attributes

Inherited from:
PartialRequestBuilder

Attributes

Inherited from:
PartialRequestBuilder

Attributes

Inherited from:
PartialRequestBuilder
def body(fs: Seq[(String, String)], encoding: String): Request[T]

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

Inherited from:
PartialRequestBuilder
def body(fs: (String, String)*): Request[T]

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

Inherited from:
PartialRequestBuilder
def body(fs: Map[String, String], encoding: String): Request[T]

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

Inherited from:
PartialRequestBuilder
def body(fs: Map[String, String]): Request[T]

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

Inherited from:
PartialRequestBuilder
def body(b: InputStream): Request[T]

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:
PartialRequestBuilder
def body(b: ByteBuffer): Request[T]

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:
PartialRequestBuilder
def body(b: Array[Byte]): Request[T]

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

Inherited from:
PartialRequestBuilder
def body(b: String, encoding: String): Request[T]

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

Inherited from:
PartialRequestBuilder
def body(b: String): Request[T]

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

Inherited from:
PartialRequestBuilder
def body[B : BodySerializer](b: B): Request[T]

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:
PartialRequestExtensions
def body(file: File): Request[T]

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:
PartialRequestExtensions
def contentLength(l: Long): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def contentLength: Option[Long]

Attributes

Inherited from:
HasHeaders
def contentType(ct: String, encoding: String): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def contentType(mt: MediaType): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def contentType(ct: String): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def contentType: Option[String]

Attributes

Inherited from:
HasHeaders
def cookies(nvs: (String, String)*): Request[T]

Adds the given cookies. Any previously defined cookies are left intact.

Adds the given cookies. Any previously defined cookies are left intact.

Attributes

Inherited from:
PartialRequestBuilder
def cookies(cs: Iterable[CookieWithMeta]): Request[T]

Adds the given cookies. Any previously defined cookies are left intact.

Adds the given cookies. Any previously defined cookies are left intact.

Attributes

Inherited from:
PartialRequestBuilder
def cookies(r: Response[_]): Request[T]

Adds the cookies from the given response. Any previously defined cookies are left intact.

Adds the cookies from the given response. Any previously defined cookies are left intact.

Attributes

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

Attributes

Inherited from:
HasHeaders
def delete(uri: Uri): Request[T]

Attributes

Inherited from:
PartialRequestBuilder

Attributes

Inherited from:
PartialRequestBuilder
def followRedirects(fr: Boolean): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def get(uri: Uri): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def head(uri: Uri): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def header(k: String, ov: Option[String]): Request[T]

Adds the given header to the headers of this request, if the value is defined. Otherwise has no effect. If a header with the same name already exists, it's replaced.

Adds the given header to the headers of this request, if the value is defined. Otherwise has no effect. If a header with the same name already exists, it's replaced.

Attributes

Inherited from:
PartialRequestBuilder
def header(k: String, v: String): Request[T]

Adds the given header to the headers of this request. If a header with the same name already exists, it's replaced.

Adds the given header to the headers of this request. If a header with the same name already exists, it's replaced.

Attributes

Inherited from:
PartialRequestBuilder
def header(k: String, v: String, onDuplicate: DuplicateHeaderBehavior): Request[T]

Adds the given header to the headers of this request.

Adds the given header to the headers of this request.

Value parameters

onDuplicate

What should happen if there's already a header with the same name. See header.

Attributes

Inherited from:
PartialRequestBuilder
def header(h: Header, onDuplicate: DuplicateHeaderBehavior): Request[T]

Adds the given header to the headers of this request. If a header with the same name already exists, the default is to replace it with the given one.

Adds the given header to the headers of this request. If a header with the same name already exists, the default is to replace it with the given one.

Value parameters

onDuplicate

What should happen if there's already a header with the same name. The default is to replace.

Attributes

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

Attributes

Inherited from:
HasHeaders
def headers(hs: Header*): Request[T]

Adds the given headers to the headers of this request. If a header with the same name already exists, it's replaced.

Adds the given headers to the headers of this request. If a header with the same name already exists, it's replaced.

Attributes

Inherited from:
PartialRequestBuilder
def headers(hs: Map[String, String]): Request[T]

Adds the given headers to the headers of this request. If a header with the same name already exists, it's replaced.

Adds the given headers to the headers of this request. If a header with the same name already exists, it's replaced.

Attributes

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

Attributes

Inherited from:
HasHeaders
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

Inherited from:
PartialRequestBuilder
def httpVersion(version: HttpVersion): Request[T]

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

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

Value parameters

version:

one of values from HttpVersion enum.

Attributes

Returns

request with version tag

Inherited from:
PartialRequestBuilder
def isWebSocket: Boolean

Attributes

Inherited from:
GenericRequest
def logSettings(loggingOptions: Option[LoggingOptions]): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def logSettings(logRequestBody: Option[Boolean], logResponseBody: Option[Boolean], logRequestHeaders: Option[Boolean], logResponseHeaders: Option[Boolean]): Request[T]

Will only have effect when using the LoggingBackend

Will only have effect when using the LoggingBackend

Attributes

Inherited from:
PartialRequestBuilder

Attributes

Inherited from:
PartialRequestBuilder
def maxRedirects(n: Int): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def multipartBody(p1: Part[BasicBodyPart], ps: Part[BasicBodyPart]*): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def multipartBody(ps: Seq[Part[BasicBodyPart]]): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def onlyMetadata: RequestMetadata

Metadata of the request, which doesn't retain the request body, or the response handling specification.

Metadata of the request, which doesn't retain the request body, or the response handling specification.

Attributes

Inherited from:
GenericRequest
def options(uri: Uri): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def patch(uri: Uri): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def post(uri: Uri): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Attributes

Inherited from:
PartialRequestBuilder
def put(uri: Uri): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def readTimeout(t: Duration): Request[T]

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

Inherited from:
PartialRequestBuilder
def redirectToGet(r: Boolean): Request[T]

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

Inherited from:
PartialRequestBuilder
def show(includeBody: Boolean, includeHeaders: Boolean, sensitiveHeaders: Set[String]): String

Attributes

Inherited from:
PartialRequestBuilder
def tag(k: String): Option[Any]

Attributes

Inherited from:
PartialRequestBuilder
def tag(k: String, v: Any): Request[T]

Attributes

Inherited from:
PartialRequestBuilder
def toCurl(sensitiveHeaders: Set[String], omitAcceptEncoding: Boolean): String

Attributes

Inherited from:
GenericRequest
def toCurl(omitAcceptEncoding: Boolean): String

Attributes

Inherited from:
GenericRequest
def toCurl(sensitiveHeaders: Set[String]): String

Attributes

Inherited from:
GenericRequest
def toCurl: String

Attributes

Inherited from:
GenericRequest
def toRfc2616Format(sensitiveHeaders: Set[String]): String

Attributes

Inherited from:
GenericRequest
def toRfc2616Format: String

Attributes

Inherited from:
GenericRequest
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
RequestMetadata -> Any
Inherited from:
RequestMetadata
def unsafeCookies: Seq[CookieWithMeta]

Attributes

Inherited from:
HasHeaders
def withBody(body: BasicBody): Request[T]

Attributes

Inherited from:
PartialRequestBuilder