Package play.libs.ws

Interface WSRequest

All Superinterfaces:
play.libs.ws.StandaloneWSRequest
All Known Implementing Classes:
AhcWSRequest

public interface WSRequest extends play.libs.ws.StandaloneWSRequest
This is the main interface to building a WS request in Java.

Note that this interface does not expose properties that are only exposed after building the request: notably, the URL, headers and query parameters are shown before an OAuth signature is calculated.

  • Method Details

    • get

      Perform a GET on the request asynchronously.
      Specified by:
      get in interface play.libs.ws.StandaloneWSRequest
      Returns:
      a promise to the response
    • patch

      CompletionStage<WSResponse> patch(play.libs.ws.BodyWritable body)
      Perform a PATCH on the request asynchronously.
      Specified by:
      patch in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      body - represented as BodyWritable
      Returns:
      a promise to the response
    • patch

      Perform a PATCH on the request asynchronously.
      Parameters:
      body - represented as String
      Returns:
      a promise to the response
    • patch

      CompletionStage<WSResponse> patch(com.fasterxml.jackson.databind.JsonNode body)
      Perform a PATCH on the request asynchronously.
      Parameters:
      body - represented as JSON
      Returns:
      a promise to the response
    • patch

      Perform a PATCH on the request asynchronously.
      Parameters:
      body - represented as a Document
      Returns:
      a promise to the response
    • patch

      Deprecated.
      Deprecated as of 2.7.0. Use patch(BodyWritable) instead.
      Perform a PATCH on the request asynchronously.
      Parameters:
      body - represented as an InputStream
      Returns:
      a promise to the response
    • patch

      Perform a PATCH on the request asynchronously.
      Parameters:
      body - represented as a File
      Returns:
      a promise to the response
    • patch

      Perform a PATCH on the request asynchronously.
      Parameters:
      body - represented as a MultipartFormData.Part
      Returns:
      a promise to the response
    • post

      CompletionStage<WSResponse> post(play.libs.ws.BodyWritable body)
      Perform a POST on the request asynchronously.
      Specified by:
      post in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      body - represented as body writable
      Returns:
      a promise to the response
    • post

      Perform a POST on the request asynchronously.
      Parameters:
      body - represented as String
      Returns:
      a promise to the response
    • post

      CompletionStage<WSResponse> post(com.fasterxml.jackson.databind.JsonNode body)
      Perform a POST on the request asynchronously.
      Parameters:
      body - represented as JSON
      Returns:
      a promise to the response
    • post

      Perform a POST on the request asynchronously.
      Parameters:
      body - represented as a Document
      Returns:
      a promise to the response
    • post

      Deprecated.
      Deprecated as of 2.6.0. Use post(BodyWritable) instead.
      Perform a POST on the request asynchronously.
      Parameters:
      body - represented as an InputStream
      Returns:
      a promise to the response
    • post

      Perform a POST on the request asynchronously.
      Parameters:
      body - represented as a File
      Returns:
      a promise to the response
    • post

      Perform a POST on the request asynchronously.
      Parameters:
      body - represented as a MultipartFormData.Part
      Returns:
      a promise to the response
    • put

      CompletionStage<WSResponse> put(play.libs.ws.BodyWritable body)
      Perform a PUT on the request asynchronously.
      Specified by:
      put in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      body - represented as BodyWritable
      Returns:
      a promise to the response
    • put

      Perform a PUT on the request asynchronously.
      Parameters:
      body - represented as String
      Returns:
      a promise to the response
    • put

      CompletionStage<WSResponse> put(com.fasterxml.jackson.databind.JsonNode body)
      Perform a PUT on the request asynchronously.
      Parameters:
      body - represented as JSON
      Returns:
      a promise to the response
    • put

      Perform a PUT on the request asynchronously.
      Parameters:
      body - represented as a Document
      Returns:
      a promise to the response
    • put

      Deprecated.
      Deprecated as of 2.7.0. Use put(BodyWritable) instead.
      Perform a PUT on the request asynchronously.
      Parameters:
      body - represented as an InputStream
      Returns:
      a promise to the response
    • put

      Perform a PUT on the request asynchronously.
      Parameters:
      body - represented as a File
      Returns:
      a promise to the response
    • put

      Perform a PUT on the request asynchronously.
      Parameters:
      body - represented as a MultipartFormData.Part
      Returns:
      a promise to the response
    • delete

      Perform a DELETE on the request asynchronously.
      Specified by:
      delete in interface play.libs.ws.StandaloneWSRequest
      Returns:
      a promise to the response
    • head

      Perform a HEAD on the request asynchronously.
      Specified by:
      head in interface play.libs.ws.StandaloneWSRequest
      Returns:
      a promise to the response
    • options

      Perform an OPTIONS on the request asynchronously.
      Specified by:
      options in interface play.libs.ws.StandaloneWSRequest
      Returns:
      a promise to the response
    • execute

      CompletionStage<WSResponse> execute(String method)
      Execute an arbitrary method on the request asynchronously.
      Specified by:
      execute in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      method - The method to execute
      Returns:
      a promise to the response
    • execute

      Execute an arbitrary method on the request asynchronously. Should be used with setMethod().
      Specified by:
      execute in interface play.libs.ws.StandaloneWSRequest
      Returns:
      a promise to the response
    • stream

      Execute this request and stream the response body.
      Specified by:
      stream in interface play.libs.ws.StandaloneWSRequest
      Returns:
      a promise to the streaming response
    • setMethod

      WSRequest setMethod(String method)
      Sets the HTTP method this request should use, where the no args execute() method is invoked.
      Specified by:
      setMethod in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      method - the HTTP method.
      Returns:
      the modified WSRequest.
    • setBody

      WSRequest setBody(play.libs.ws.BodyWritable body)
      Set the body this request should use.
      Specified by:
      setBody in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      body - the body of the request.
      Returns:
      the modified WSRequest.
    • setBody

      WSRequest setBody(String body)
      Set the body this request should use.
      Parameters:
      body - the body of the request.
      Returns:
      the modified WSRequest.
    • setBody

      WSRequest setBody(com.fasterxml.jackson.databind.JsonNode body)
      Set the body this request should use.
      Parameters:
      body - the body of the request.
      Returns:
      the modified WSRequest.
    • setBody

      Deprecated.
      Deprecated as of 2.6.0. Use setBody(BodyWritable) instead.
      Set the body this request should use.
      Parameters:
      body - the request body.
      Returns:
      the modified WSRequest.
    • setBody

      WSRequest setBody(File body)
      Set the body this request should use.
      Parameters:
      body - the body of the request.
      Returns:
      the modified WSRequest.
    • setBody

      <U> WSRequest setBody(Source<ByteString,U> body)
      Set the body this request should use.
      Parameters:
      body - the body of the request.
      Returns:
      the modified WSRequest.
    • addHeader

      WSRequest addHeader(String name, String value)
      Adds a header to the request. Note that duplicate headers are allowed by the HTTP specification, and removing a header is not available through this API.
      Specified by:
      addHeader in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      name - the header name
      value - the header value
      Returns:
      the modified WSRequest.
    • setHeader

      @Deprecated WSRequest setHeader(String name, String value)
      Deprecated.
      Adds a header to the request. Note that duplicate headers are allowed by the HTTP specification, and removing a header is not available through this API.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      the modified WSRequest.
    • setHeaders

      WSRequest setHeaders(Map<String,List<String>> headers)
      Sets all of the headers on the request.
      Specified by:
      setHeaders in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      headers - the headers
      Returns:
      the modified WSRequest.
    • setQueryString

      WSRequest setQueryString(String query)
      Sets the query string to query.
      Specified by:
      setQueryString in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      query - the fully formed query string
      Returns:
      the modified WSRequest.
    • setQueryString

      WSRequest setQueryString(Map<String,List<String>> params)
      Sets the query string to query.
      Specified by:
      setQueryString in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      params - the query string parameters
      Returns:
      the modified WSRequest.
    • addQueryParameter

      WSRequest addQueryParameter(String name, String value)
      Sets a query parameter with the given name, this can be called repeatedly. Duplicate query parameters are allowed.
      Specified by:
      addQueryParameter in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      name - the query parameter name
      value - the query parameter value
      Returns:
      the modified WSRequest.
    • setQueryParameter

      @Deprecated WSRequest setQueryParameter(String name, String value)
      Sets a query parameter with the given name, this can be called repeatedly. Duplicate query parameters are allowed.
      Parameters:
      name - the query parameter name
      value - the query parameter value
      Returns:
      the modified WSRequest.
    • addCookie

      WSRequest addCookie(play.libs.ws.WSCookie cookie)
      Adds a cookie to the request
      Specified by:
      addCookie in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      cookie - the cookie to add.
      Returns:
      the modified request
    • addCookie

      WSRequest addCookie(Http.Cookie cookie)
      Adds a cookie to the request
      Parameters:
      cookie - the cookie to add.
      Returns:
      the modified request
    • addCookies

      WSRequest addCookies(play.libs.ws.WSCookie... cookies)
      Sets several cookies on the request.
      Specified by:
      addCookies in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      cookies - the cookies.
      Returns:
      the modified request
    • setCookies

      WSRequest setCookies(List<play.libs.ws.WSCookie> cookies)
      Sets all the cookies on the request.
      Specified by:
      setCookies in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      cookies - all the cookies.
      Returns:
      the modified request
    • setAuth

      WSRequest setAuth(String userInfo)
      Sets the authentication header for the current request using BASIC authentication.
      Specified by:
      setAuth in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      userInfo - a string formed as "username:password".
      Returns:
      the modified WSRequest.
    • setAuth

      WSRequest setAuth(String username, String password)
      Sets the authentication header for the current request using BASIC authentication.
      Specified by:
      setAuth in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      username - the basic auth username
      password - the basic auth password
      Returns:
      the modified WSRequest.
    • setAuth

      WSRequest setAuth(String username, String password, play.libs.ws.WSAuthScheme scheme)
      Sets the authentication header for the current request.
      Specified by:
      setAuth in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      username - the username
      password - the password
      scheme - authentication scheme
      Returns:
      the modified WSRequest.
    • sign

      WSRequest sign(play.libs.ws.WSSignatureCalculator calculator)
      Sets an (OAuth) signature calculator.
      Specified by:
      sign in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      calculator - the signature calculator
      Returns:
      the modified WSRequest
    • setFollowRedirects

      WSRequest setFollowRedirects(boolean followRedirects)
      Sets whether redirects (301, 302) should be followed automatically.
      Specified by:
      setFollowRedirects in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      followRedirects - true if the request should follow redirects
      Returns:
      the modified WSRequest
    • setVirtualHost

      WSRequest setVirtualHost(String virtualHost)
      Sets the virtual host as a "hostname:port" string.
      Specified by:
      setVirtualHost in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      virtualHost - the virtual host
      Returns:
      the modified WSRequest
    • setRequestTimeout

      WSRequest setRequestTimeout(Duration timeout)
      Sets the request timeout in milliseconds.
      Specified by:
      setRequestTimeout in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      timeout - the request timeout in milliseconds. A value of -1 indicates an infinite request timeout.
      Returns:
      the modified WSRequest.
    • setRequestTimeout

      @Deprecated WSRequest setRequestTimeout(long timeout)
      Sets the request timeout in milliseconds.
      Parameters:
      timeout - the request timeout in milliseconds. A value of -1 indicates an infinite request timeout.
      Returns:
      the modified WSRequest.
    • setRequestFilter

      WSRequest setRequestFilter(play.libs.ws.WSRequestFilter filter)
      Adds a request filter.
      Specified by:
      setRequestFilter in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      filter - a transforming filter.
      Returns:
      the modified request.
    • setContentType

      WSRequest setContentType(String contentType)
      Set the content type. If the request body is a String, and no charset parameter is included, then it will default to UTF-8.
      Specified by:
      setContentType in interface play.libs.ws.StandaloneWSRequest
      Parameters:
      contentType - The content type
      Returns:
      the modified WSRequest
    • getUrl

      String getUrl()
      Specified by:
      getUrl in interface play.libs.ws.StandaloneWSRequest
      Returns:
      the URL of the request. This has not passed through an internal request builder and so will not be signed.
    • getHeaders

      Map<String,List<String>> getHeaders()
      Specified by:
      getHeaders in interface play.libs.ws.StandaloneWSRequest
      Returns:
      the headers (a copy to prevent side-effects). This has not passed through an internal request builder and so will not be signed.
    • getQueryParameters

      Map<String,List<String>> getQueryParameters()
      Specified by:
      getQueryParameters in interface play.libs.ws.StandaloneWSRequest
      Returns:
      the query parameters (a copy to prevent side-effects). This has not passed through an internal request builder and so will not be signed.