Provide an implicit value of this type to serialize arbitrary classes into a request body.
Provide an implicit value of this type to serialize arbitrary classes into a request body. Backends might also provide special logic for serializer instances which they define (e.g. to handle streaming).
A base class for delegate backends, which includes delegating implementations for close
and responseMonad
, so
that only send
needs to be defined.
A synchronous backend that safely wraps SttpBackend exceptions in Either[Throwable, *]
's
A synchronous backend that safely wraps SttpBackend exceptions in Either[Throwable, *]
's
TODO
The effect type
Type of supported byte streams, Nothing
if none
Capabilities supported by the backend. See SttpBackend.
The low-level type of the body, read using a HttpResponse.BodyHandler read by HttpClient.
The higher-level body to which BH
is transformed (e.g. a backend-native stream representation), which then is
used to read the body as described by responseAs
.
A RequestT without the method & uri specified (which cannot yet be sent).
A RequestT with the method & uri specified.
A RequestT with the method & uri specified. Such a request can be sent.
Describes a HTTP request, along with a description of how the response body should be handled.
Describes a HTTP request, along with a description of how the response body should be handled.
The request can be sent:
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.
The target type, to which the response body should be read.
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).
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.
Request-specific tags which can be used by backends for logging, metrics, etc. Not used by default.
If redirects are followed, and there were redirects, contains responses for the intermediate requests. The first response (oldest) comes first.
Describes how response body should be handled.
Describes how response body should be handled.
Apart from the basic cases (ignoring, reading as a byte array or file), response body descriptions can be mapped over, to support custom types. The mapping can take into account the ResponseMetadata, that is the headers and status code. Responses can also be handled depending on the response metadata. Finally, two response body descriptions can be combined (with some restrictions).
A number of as[Type]
helper methods are available as part of SttpApi and when importing sttp.client3._
.
Target type as which the response will be read.
The backend capabilities required by the 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 WebSockets (the ability to handle websocket requests).
A simple, synchronous http client.
A simple, synchronous http client. Usage example:
import sttp.client3.{SimpleHttpClient, UriContext, basicRequest} val client = SimpleHttpClient() val request = basicRequest.get(uri"https://httpbin.org/get") val response = client.send(request) println(response.body)
Wraps an SttpBackend, which can be substituted or modified using wrapBackend, adding e.g. logging.
Creating a client allocates resources, hence when no longer needed, the client should be closed using close.
A backend is used to send HTTP requests described by RequestT.
A backend is used to send HTTP requests described by RequestT. Backends might wrap Java or Scala HTTP clients, or other backends.
The effect type used when returning responses. E.g. Identity for synchronous backends, scala.concurrent.Future for asynchronous backends.
Capabilities supported by this backend, in addition to Effect. This might be Any
(no special capabilities),
Streams (the ability to send and receive streaming bodies) or WebSockets (the ability to handle websocket
requests).
Backends should try to classify exceptions into one of the categories specified by SttpClientException. Other exceptions should be thrown unchanged.
Known exceptions that might occur when using a backend.
Known exceptions that might occur when using a backend. Currently this covers:
In general, it's safe to assume that the request hasn't been sent in case of connect exceptions. With read exceptions, the target host might or might have not received and processed the request.
The SttpBackend.send methods might also throw other exceptions, due to programming errors, bugs in the underlying implementations, bugs in sttp or an uncovered exception.
A synchronous backend that safely wraps SttpBackend exceptions in Try
's
A synchronous backend that safely wraps SttpBackend exceptions in Try
's
TODO
(Since version 3.0.0) use DeserializationException
(Since version 3.0.0) use ResponseException
Use both l
and r
to read the response body.
Use both l
and r
to read the response body. Neither response specifications may use streaming or web sockets.
Use l
to read the response body.
Use l
to read the response body. If the raw body value which is used by l
is replayable (a file or byte
array), also use r
to read the response body. Otherwise ignore r
(if the raw body is a stream or a web
socket).
Uses the onSuccess
response specification for successful responses (2xx), and the onError
specification
otherwise.
Uses the onSuccess
response specification for successful responses (2xx), and the onError
specification
otherwise.
Use the given charset by default, unless specified otherwise in the response headers.
Use the given charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Use the given charset by default, unless specified otherwise in the response headers.
Use the given charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Use the given charset by default, unless specified otherwise in the response headers.
Use the given charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Use the utf-8
charset by default, unless specified otherwise in the response headers.
Uses the onSuccess
response specification for 101 responses (switching protocols) on JVM/Native, 200 responses
on JS.
Uses the onSuccess
response specification for 101 responses (switching protocols) on JVM/Native, 200 responses
on JS. Otherwise, use the onError
specification.
A starting request, with the following modification comparing to emptyRequest
: Accept-Encoding
is set to
gzip, deflate
(compression/decompression is handled automatically by the library).
A starting request, with the following modification comparing to emptyRequest
: Accept-Encoding
is set to
gzip, deflate
(compression/decompression is handled automatically by the library).
Reads the response body as an Either[String, String]
, where Left
is used if the status code is non-2xx, and
Right
otherwise.
An empty request with no headers.
An empty request with no headers.
Reads the response body as an Either[String, String]
, where Left
is used if the status code is non-2xx, and
Right
otherwise.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Encodes the given parameters as form data.
Encodes the given parameters as form data.
Content type will be set to application/x-www-form-urlencoded
, can be overridden later using the contentType
method.
Encodes the given parameters as form data using utf-8
.
Encodes the given parameters as form data using utf-8
.
Content type will be set to application/x-www-form-urlencoded
, can be overridden later using the contentType
method.
Encodes the given parameters as form data.
Encodes the given parameters as form data.
Content type will be set to application/x-www-form-urlencoded
, can be overridden later using the contentType
method.
Encodes the given parameters as form data using utf-8
.
Encodes the given parameters as form data using utf-8
.
Content type will be set to application/x-www-form-urlencoded
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to text/plain
with given encoding, can be overridden later using the contentType
method.
Content type will be set to text/plain
with given encoding, can be overridden later using the contentType
method.
Content type will be set to text/plain
with utf-8
encoding, can be overridden later using the contentType
method.
Content type will be set to text/plain
with utf-8
encoding, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
File name will be set to the name of the file.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
File name will be set to the name of the file.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
Content type will be set to application/octet-stream
, can be overridden later using the contentType
method.
A starting request which always reads the response body as a string, regardless of the status code.
A starting request which always reads the response body as a string, regardless of the status code.