If you are calling out to an unreliable network, consider using Futures.timeout and a circuit breaker like Failsafe. You should size the pool to leave a safety margin large enough to account for failures. If you are doing any blocking work, including any kind of DNS work such as calling (), then you should use a custom execution context as described in ThreadPools, preferably through a CustomExecutionContext. This returns a Future where the Response contains the data returned from the server. val futureResponse: Future = complexRequest.get() This ends the chain, and uses all the options defined on the built request in the WSRequest. You end by calling a method corresponding to the HTTP method you want to use. addQueryStringParameters("search" -> "play") addHttpHeaders("Accept" -> "application/json") You can chain calls together to construct complex requests. This returns a WSRequest that you can use to specify various HTTP options, such as setting headers. To build an HTTP request, you start with ws.url() to specify the URL. We’ve called the WSClient instance ws, all the following examples will assume this name. Now any component that wants to use WS will have to declare a dependency on the WSClient: import Ĭlass Application (ws: WSClient, val controllerComponents: ControllerComponents) extends BaseController Using an HTTP cache means savings on repeated requests to backend REST services, and is especially useful when combined with resiliency features such as stale-on-error and stale-while-revalidate. Once you have the library dependencies, then enable the HTTP cache as shown on WS Cache Configuration page. Or you can use another JSR-107 compatible cache such as Caffeine. You can add ehcache: libraryDependencies += ehcache Play WS supports HTTP caching, but requires a JSR-107 cache implementation to enable this feature. To use WSClient, first add ws to your build.sbt file: libraryDependencies += ws Please see the 2.6 migration guide for more information. In addition, shaded versions of AsyncHttpClient and Netty are now used in Play WS to minimize library conflicts, primarily so that Play’s HTTP engine can use a different version of Netty. Note: In Play 2.6, Play WS has been split into two, with an underlying standalone client that does not depend on Play, and a wrapper on top that uses Play specific classes. Finally, we’ll discuss some common use cases.
#Free auto clicker 2.8.2 how to
We’ll discuss how to make both GET and POST HTTP requests first, and then show how to process the response from WSClient. There are two important parts to using the WSClient: making a request, and processing the response.
Play supports this via its WS (“WebService”) library, which provides a way to make asynchronous HTTP calls through a WSClient instance. Sometimes we would like to call other HTTP services from within a Play application. English ▾ English българин Français 日本語 Türkçe Calling REST APIs with Play WS