Class AhcWSClient

  • All Implemented Interfaces:
    Closeable, AutoCloseable, WSClient

    public class AhcWSClient
    extends Object
    implements WSClient
    A WS client backed by AsyncHttpClient implementation.

    See https://www.playframework.com/documentation/latest/JavaWS for documentation.

    • Constructor Detail

      • AhcWSClient

        public AhcWSClient​(play.shaded.ahc.org.asynchttpclient.AsyncHttpClient client,
                           Materializer materializer)
      • AhcWSClient

        @Inject
        public AhcWSClient​(play.libs.ws.ahc.StandaloneAhcWSClient client,
                           Materializer materializer)
    • Method Detail

      • create

        public static AhcWSClient create​(play.api.libs.ws.ahc.AhcWSClientConfig config,
                                         play.api.libs.ws.ahc.cache.AhcHttpCache cache,
                                         Materializer materializer)
        Creates WS client manually from configuration, internally creating a new instance of AsyncHttpClient and managing its own thread pool.

        This client is not managed as part of Play's lifecycle, and must be closed by calling ws.close(), otherwise you will run into memory leaks.

        Parameters:
        config - a config object, usually from AhcWSClientConfigFactory
        cache - if not null, provides HTTP caching.
        materializer - an Akka materializer
        Returns:
        a new instance of AhcWSClient.
      • getUnderlying

        public Object getUnderlying()
        Description copied from interface: WSClient
        The underlying implementation of the client, if any. You must cast the returned value to the type you want.
        Specified by:
        getUnderlying in interface WSClient
        Returns:
        the backing object.
      • asScala

        public play.api.libs.ws.WSClient asScala()
        Specified by:
        asScala in interface WSClient
        Returns:
        the Scala version for this WSClient.
      • url

        public WSRequest url​(String url)
        Description copied from interface: WSClient
        Returns a WSRequest object representing the URL. You can append additional properties on the WSRequest by chaining calls, and execute the request to return an asynchronous Promise<WSResponse>.
        Specified by:
        url in interface WSClient
        Parameters:
        url - the URL to request
        Returns:
        the request
      • getStandaloneWSClient

        public play.libs.ws.StandaloneWSClient getStandaloneWSClient()
        Return the implementation interface of StandaloneAhcWSClient.
        Returns:
        StandaloneWSClient