trait Client extends Service
An HTTP client.
val eventuallyContent = client(Get("/hello")).flatMap { response => response.readAs[String] }
An HTTP client is a Service function. It handles HTTP requests and eventually returns HTTP responses.
A client maintains several TCP connections to the remote server. These connections are used to send requests and are blocked until the corresponding response has been received. If no connection is available when a new request comes, it waits for one connection to become available.
It is important that the user code completly consumes the response content stream, so
the connection is freed for the next request. That's why it is better to use the run
operation if possible since this one automatically drains the request upon return.
If the request to execute does not specify an Host header, it will be automatically added
and set to the value of the client host
.
- Source
- Client.scala
- Alphabetic
- By Inheritance
- Client
- Function1
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
implicit abstract
def
executor: ExecutionContext
The ExecutionContext that will be used to run the user code.
-
abstract
def
host: String
The host this client is connected to.
-
abstract
def
maxConnections: Int
The maximum number of TCP connections maintained with the remote server.
-
abstract
def
port: Int
The port this client is connected to.
-
abstract
def
protocol: String
The protocol used by this client.
-
abstract
def
scheme: String
The scheme used by this client (either HTTP or HTTPS if connected in SSL).
-
abstract
def
ssl: ClientConfiguration
The SSL configuration used by the client.
The SSL configuration used by the client. Must be provided if the server certificate is not recognized by default.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
andThen[A](g: (IO[Response]) ⇒ A): (Request) ⇒ A
- Definition Classes
- Function1
- Annotations
- @unspecialized()
-
def
apply(request: Request, timeout: FiniteDuration = FiniteDuration(30, "seconds")): IO[Response]
Send a request to the server and eventually give back the response.
Send a request to the server and eventually give back the response.
- request
the HTTP request to be sent to the server.
- timeout
maximum amount of time allowed to retrieve the response.
- returns
eventually the HTTP response.
-
def
apply(request: Request): IO[Response]
Send a request to the server and eventually give back the response.
Send a request to the server and eventually give back the response.
- request
the HTTP request to be sent to the server.
- returns
eventually the HTTP response.
- Definition Classes
- Client → Function1
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
compose[A](g: (A) ⇒ Request): (A) ⇒ IO[Response]
- Definition Classes
- Function1
- Annotations
- @unspecialized()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
isClosed: Boolean
Check if this client is already closed (ie.
Check if this client is already closed (ie. it does not accept any more requests).
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
openedConnections: Int
The number of TCP connections currently opened with the remote server.
-
def
run[A](request: Request, timeout: FiniteDuration = FiniteDuration(30, "seconds"))(f: (Response) ⇒ IO[A] = (_: Response) => IO.unit): IO[A]
Send this request to the server, eventually run the given function and return the result.
Send this request to the server, eventually run the given function and return the result. This operation ensures that the response content stream is fully read even if the provided user code do not consume it. The response is drained as soon as the
f
function returns.- request
the HTTP request to be sent to the server.
- timeout
maximum amount of time allowed to retrieve the response and extract the return value.
- f
a function that eventually receive the response and transform it to a value of type
A
.- returns
eventually a value of type
A
.
-
def
runAndStop[A](f: (Client) ⇒ IO[A]): IO[A]
Run the given function and close the client.
Run the given function and close the client.
- f
a function that take a client and eventually return a value of type
A
.- returns
eventually a value of type
A
.
-
def
runAndStopSync[A](f: (Client) ⇒ IO[A]): A
Run the given function and close the client.
Run the given function and close the client. This operation is blocking and the calling thread will wait for the call to be completed.
- f
a function that take a client and eventually return a value of type
A
.- returns
a value of type
A
.
-
def
runSync[A](request: Request, timeout: FiniteDuration = FiniteDuration(30, "seconds"))(f: (Response) ⇒ IO[A] = (_: Response) => IO.unit): A
Send this request to the server, eventually run the given function and return the result.
Send this request to the server, eventually run the given function and return the result. This operation ensures that the response content stream is fully read even if the provided user code do not consume it. The response is drained as soon as the
f
function returns. This operation is block and the calling thread will wait for the call to be completed.- request
the HTTP request to be sent to the server.
- timeout
maximum amount of time allowed to retrieve the response and extract the return value.
- f
a function that eventually receive the response and transform it to a value of type
A
.- returns
a value of type
A
.
-
def
stop(): IO[Unit]
Stop the client and kill all current and waiting requests.
Stop the client and kill all current and waiting requests. This operation returns an
IO
and is lazy. If you want to stop the client immediatly and synchronously use stopSync instead.- returns
a IO effect resolved as soon as the client is shutdown.
-
def
stopSync(): Unit
Stop the client and kill all current and waiting requests right away.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- Client → Function1 → AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )