Packages

object Client

Build HTTP clients.

val client = Client("github.com")
val fetchGithubHomePage: IO[String] =
  for {
    homePage <- client.run(Get("/"))(_.readAs[String])
    _ <- client.stop()
  } yield (homePage)
println(fetchGithubHomePage.unsafeRunSync)

Once created an HTTP client maintains several TCP connections to the remote server, and can be reused to run several requests. It is better to create a dedicated client this way if you plan to send many requests to the same server.

However there are some situations where you have a single request to run, or you have a batch of requests to send over an unknown set of servers. In this case you can use the run operation that automatically create a temporary HTTP client to run the request and trash it after the exchange completion.

val homePage = Client.run(Get("http://github.com/"))(_.readAs[String])

Note that in this case, for each request, a new client (including the whole IO infrastructure) will to be created, and a new TCP connection will be opened to the server.

Source
Client.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Client
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

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 apply(host: String, port: Int = 80, scheme: String = "http", ssl: ClientConfiguration = SSL.ClientConfiguration.default, protocol: String = HTTP, maxConnections: Int = 10)(implicit executor: ExecutionContext): Client

    Create a new HTTP Client for the provided host/port.

    Create a new HTTP Client for the provided host/port.

    host

    the host to use to setup the TCP connections.

    port

    the port to use to setup the TCP connections.

    scheme

    either http or https.

    ssl

    if provided the custom SSL configuration to use for this client.

    protocol

    the protocol to use for this client (HTTP or HTTP/2).

    maxConnections

    the maximum number of TCP connections to maintain with the remote server.

    executor

    the scala.concurrent.ExecutionContext to use to run user code.

    returns

    an HTTP client instance.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. def run[A](request: Request, followRedirects: Boolean = true, timeout: FiniteDuration = FiniteDuration(30, "seconds"), protocol: String = HTTP)(f: (Response) ⇒ IO[A] = (_: Response) => IO.unit)(implicit executor: ExecutionContext, ssl: ClientConfiguration): IO[A]

    Run the provided request with a temporary client, and apply the f function to the response.

    Run the provided request with a temporary client, and apply the f function to the response.

    request

    the request to run. It must include a proper Host header.

    followRedirects

    if true follow the intermediate HTTP redirects. Default to true.

    timeout

    maximum amount of time allowed to retrieve the response and extract the return value.

    protocol

    the protocol to use for this client (HTTP or HTTP/2).

    f

    a function that eventually receive the response and transform it to a value of type A.

    returns

    eventually a value of type A.

  17. def runSync[A](request: Request, followRedirects: Boolean = true, timeout: FiniteDuration = FiniteDuration(30, "seconds"), protocol: String = HTTP)(f: (Response) ⇒ IO[A] = (_: Response) => IO.unit)(implicit executor: ExecutionContext, ssl: ClientConfiguration): A

    Run the provided request with a temporary client, and apply the f function to the response.

    Run the provided request with a temporary client, and apply the f function to the response. This operation is blocking and the calling thread will wait for the request to be completed.

    request

    the request to run. It must include a proper Host header.

    followRedirects

    if true follow the intermediate HTTP redirects. Default to true.

    timeout

    maximum amount of time allowed to retrieve the response and extract the return value.

    protocol

    the protocol to use for this client (HTTP or HTTP/2).

    f

    a function that eventually receive the response and transform it to a value of type A.

    returns

    synchronously a value of type A.

  18. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  19. def toString(): String
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped