StandaloneAhcWSResponse

play.api.libs.ws.ahc.StandaloneAhcWSResponse
See theStandaloneAhcWSResponse companion object
class StandaloneAhcWSResponse(ahcResponse: Response) extends StandaloneWSResponse, DefaultBodyReadables, WSCookieConverter, AhcUtilities

A WS HTTP response backed by org.asynchttpclient.Response.

Attributes

Companion
object
Graph
Supertypes
trait AhcUtilities
trait DefaultBodyReadables
trait StandaloneWSResponse
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def status: Int

The response status code.

The response status code.

Attributes

Definition Classes
StandaloneWSResponse
override def statusText: String

The response status message.

The response status message.

Attributes

Definition Classes
StandaloneWSResponse
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
override def underlying[T]: T

Get the underlying response object.

Get the underlying response object.

Attributes

Definition Classes
StandaloneWSResponse
override def uri: URI

Returns the URI for this response, which can differ from the request one in case of redirection.

Returns the URI for this response, which can differ from the request one in case of redirection.

Attributes

Definition Classes
StandaloneWSResponse

Inherited methods

def asCookie(c: Cookie): WSCookie

Attributes

Inherited from:
WSCookieConverter
def asCookie(cookie: WSCookie): Cookie

Attributes

Inherited from:
WSCookieConverter
def body[T : BodyReadable]: T

The response body as the given type. This renders as the given type. You must have a BodyReadable in implicit scope.

The response body as the given type. This renders as the given type. You must have a BodyReadable in implicit scope.

The simplest use case is

import play.api.libs.ws.StandaloneWSResponse
import play.api.libs.ws.DefaultBodyReadables._

def responseBodyAsString(response: StandaloneWSResponse): String =
 response.body[String]

But you can also render as JSON

// not compilable: requires `play-ws-standalone-json` dependency
import play.api.libs.json.JsValue
import play.api.libs.ws.StandaloneWSResponse

def responseBodyAsJson(response: StandaloneWSResponse): JsValue =
 response.body[JsValue]

or as binary:

import org.apache.pekko.util.ByteString
import play.api.libs.ws.StandaloneWSResponse
import play.api.libs.ws.DefaultBodyReadables._

def responseBodyAsByteString(response: StandaloneWSResponse): ByteString =
 response.body[ByteString]

Attributes

Inherited from:
StandaloneWSResponse
def contentType: String

Attributes

Returns

the content type.

Inherited from:
StandaloneWSResponse
def header(name: String): Option[String]

Get the value of the header with the specified name. If there are more than one values for this header, the first value is returned. If there are no values, than a None is returned.

Get the value of the header with the specified name. If there are more than one values for this header, the first value is returned. If there are no values, than a None is returned.

Value parameters

name

the header name

Attributes

Returns

the header value

Inherited from:
StandaloneWSResponse
def headerValues(name: String): Seq[String]

Get all the values of header with the specified name. If there are no values for the header with the specified name, than an empty sequence is returned.

Get all the values of header with the specified name. If there are no values for the header with the specified name, than an empty sequence is returned.

Value parameters

name

the header name.

Attributes

Returns

all the values for this header name.

Inherited from:
StandaloneWSResponse
def headersToMap(headers: HttpHeaders): TreeMap[String, Seq[String]]

Attributes

Inherited from:
AhcUtilities

Concrete fields

lazy override val body: String

The response body decoded as String, using a simple algorithm to guess the encoding.

The response body decoded as String, using a simple algorithm to guess the encoding.

This decodes the body to a string representation based on the following algorithm:

  1. Look for a "charset" parameter on the Content-Type. If it exists, set charset to its value and go to step 3.
  2. If the Content-Type is of type "text", set charset to "ISO-8859-1"; else set charset to "UTF-8".
  3. Decode the raw bytes of the body using charset.

Note that this does not take into account any special cases for specific content types. For example, for application/json, we do not support encoding autodetection and will trust the charset parameter if provided..

Attributes

Returns

the response body parsed as a String using the above algorithm.

lazy override val bodyAsBytes: ByteString

The response body as a byte string.

The response body as a byte string.

Attributes

lazy override val bodyAsSource: Source[ByteString, _]

Attributes

Returns

the response as a source of bytes

lazy override val cookies: Seq[WSCookie]

Get all the cookies.

Get all the cookies.

Attributes

lazy override val headers: Map[String, Seq[String]]

Returns the current headers for this response.

Returns the current headers for this response.

Attributes

Implicits

Inherited implicits

implicit val readableAsByteArray: BodyReadable[Array[Byte]]

Converts a response body into Array[Byte].

Converts a response body into Array[Byte].

import play.api.libs.ws.DefaultBodyReadables._

def example(response: play.api.libs.ws.StandaloneWSResponse): Array[Byte] =
 response.body[Array[Byte]]

Attributes

Inherited from:
DefaultBodyReadables
implicit val readableAsByteBuffer: BodyReadable[ByteBuffer]

Converts a response body into a read only ByteBuffer.

Converts a response body into a read only ByteBuffer.

import java.nio.ByteBuffer
import play.api.libs.ws.DefaultBodyReadables._

def example(response: play.api.libs.ws.StandaloneWSResponse): ByteBuffer =
 response.body[ByteBuffer]

Attributes

Inherited from:
DefaultBodyReadables
implicit val readableAsByteString: BodyReadable[ByteString]

Converts a response body into an org.apache.pekko.util.ByteString:

Converts a response body into an org.apache.pekko.util.ByteString:

import org.apache.pekko.util.ByteString
import play.api.libs.ws.DefaultBodyReadables._

def example(response: play.api.libs.ws.StandaloneWSResponse): ByteString =
 response.body[ByteString]

Attributes

Inherited from:
DefaultBodyReadables
implicit val readableAsSource: BodyReadable[Source[ByteString, _]]

Converts a response body into Source[ByteString, _].

Converts a response body into Source[ByteString, _].

Attributes

Inherited from:
DefaultBodyReadables
implicit val readableAsString: BodyReadable[String]

Converts a response body into a String.

Converts a response body into a String.

Note: this is only a best-guess effort and does not handle all content types. See StandaloneWSResponse.body:String* for more information.

import play.api.libs.ws.DefaultBodyReadables._

def example(response: play.api.libs.ws.StandaloneWSResponse): String =
 response.body[String]

Attributes

Inherited from:
DefaultBodyReadables