Packages

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
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Client
  2. Function1
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. implicit abstract def executor: ExecutionContext

    The ExecutionContext that will be used to run the user code.

  2. abstract def host: String

    The host this client is connected to.

  3. abstract def maxConnections: Int

    The maximum number of TCP connections maintained with the remote server.

  4. abstract def port: Int

    The port this client is connected to.

  5. abstract def protocol: String

    The protocol used by this client.

  6. abstract def scheme: String

    The scheme used by this client (either HTTP or HTTPS if connected in SSL).

  7. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def andThen[A](g: (IO[Response]) ⇒ A): (Request) ⇒ A
    Definition Classes
    Function1
    Annotations
    @unspecialized()
  5. 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.

  6. 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
  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  9. def compose[A](g: (A) ⇒ Request): (A) ⇒ IO[Response]
    Definition Classes
    Function1
    Annotations
    @unspecialized()
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. 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).

  16. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  20. def openedConnections: Int

    The number of TCP connections currently opened with the remote server.

  21. 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.

  22. 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.

  23. 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.

  24. 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.

  25. 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.

  26. def stopSync(): Unit

    Stop the client and kill all current and waiting requests right away.

  27. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  28. def toString(): String
    Definition Classes
    Client → Function1 → AnyRef → Any
  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from (Request) ⇒ IO[Response]

Inherited from AnyRef

Inherited from Any

Ungrouped