play.api.libs.ws

WS

Related Doc: package ws

object WS

Asynchronous API to to query web services, as an http client.

Usage example:

WS.url("http://example.com/feed").get()
WS.url("http://example.com/item").post("content")

When greater flexibility is needed, you can also create clients explicitly and pass them into WS:

implicit val client = new NingWSClient(builder.build())
WS.url("http://example.com/feed").get()

Or call the client directly:

import com.typesafe.config.ConfigFactory
import play.api.libs.ws._
import play.api.libs.ws.ning._

val configuration = play.api.Configuration(ConfigFactory.parseString(
"""
  |ws.ssl.trustManager = ...
""".stripMargin))
val parser = new DefaultWSConfigParser(configuration, Play.current.classloader)
val builder = new NingAsyncHttpClientConfigBuilder(parser.parse())
val secureClient: WSClient = new NingWSClient(builder.build())
val response = secureClient.url("https://secure.com").get()

Note that the resolution of URL is done through the magnet pattern defined in WSRequestMagnet.

The value returned is a Future[WSResponse], and you should use Play's asynchronous mechanisms to use this response.

Source
WS.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. WS
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
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. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  5. def client(implicit app: Application): WSClient

    Retrieves or creates underlying HTTP client.

    Retrieves or creates underlying HTTP client. Note that due to the Plugin architecture, an implicit application must be in scope. Most of the time you will want the current app:

    import play.api.Play.current
    val client = WS.client
  6. def clientUrl(url: String)(implicit client: WSClient): WSRequest

    Prepares a new request using an implicit client.

    Prepares a new request using an implicit client. The client must be in scope and configured, i.e.

    implicit val sslClient = new play.api.libs.ws.ning.NingWSClient(sslBuilder.build())
    WS.clientUrl("http://example.com/feed")
    url

    the URL to request

    client

    the client to use to make the request.

  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toString(): String

    Definition Classes
    AnyRef → Any
  19. def url(magnet: WSRequestMagnet): WSRequest

    Prepares a new request using a provided magnet.

    Prepares a new request using a provided magnet. This method gives you the ability to create your own URL implementations at the cost of some complexity.

    object PairMagnet {
      implicit def fromPair(pair: Pair[WSClient, java.net.URL]) =
        new WSRequestHolderMagnet {
          def apply(): WSRequestHolder = {
            val (client, netUrl) = pair
            client.url(netUrl.toString)
          }
       }
    }
    import scala.language.implicitConversions
    val client = WS.client
    val exampleURL = new java.net.URL("http://example.com")
    WS.url(client -> exampleURL).get()
    magnet

    a magnet pattern.

    See also

    The magnet pattern

  20. def url(url: String)(implicit app: Application): WSRequest

    Prepares a new request using an implicit application.

    Prepares a new request using an implicit application. This creates a default client, which you can then use to construct a request.

    import play.api.Play.current
    WS.url("http://localhost/").get()
    url

    the URL to request

    app

    the implicit application to use.

  21. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. def wsapi(implicit app: Application): WSAPI

    Attributes
    protected[play]

Inherited from AnyRef

Inherited from Any

Ungrouped