WSResponse

play.api.libs.ws.WSResponse
trait WSResponse extends StandaloneWSResponse, WSBodyReadables

A WS Response that can use Play specific classes.

Attributes

Graph
Supertypes
trait XMLBodyReadables
trait JsonBodyReadables
trait DefaultBodyReadables
trait StandaloneWSResponse
class Object
trait Matchable
class Any
Show all

Members list

Value members

Abstract methods

override def body: String

The response body as String.

The response body as String.

Attributes

Definition Classes
StandaloneWSResponse
override def bodyAsBytes: ByteString

The response body as a byte string.

The response body as a byte string.

Attributes

Definition Classes
StandaloneWSResponse
override def bodyAsSource: Source[ByteString, _]

Attributes

Returns

the response as a source of bytes

Definition Classes
StandaloneWSResponse
override def cookies: Seq[WSCookie]

Get all the cookies.

Get all the cookies.

Attributes

Definition Classes
StandaloneWSResponse
override def headers: Map[String, Seq[String]]

Return the current headers for this response.

Return the current headers for this response.

Attributes

Definition Classes
StandaloneWSResponse
def json: JsValue
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 underlying[T]: T

Get the underlying response object.

Get the underlying response object.

Attributes

Definition Classes
StandaloneWSResponse
def xml: Elem

Concrete methods

override 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, which is done with

The response body as the given type. This renders as the given type. You must have a BodyReadable in implicit scope, which is done with

class MyClass extends play.api.libs.ws.WSBodyReadables {
 // JSON and XML body readables
}

The simplest use case is

val responseBodyAsString: String = response.body[String]

But you can also render as JSON

val responseBodyAsJson: JsValue = response.body[JsValue]

or as XML:

val xml: Elem = response.body[Elem]

Attributes

Definition Classes
StandaloneWSResponse
override def contentType: String

Attributes

Returns

the content type.

Definition Classes
StandaloneWSResponse
override 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

Definition Classes
StandaloneWSResponse
override 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.

Definition Classes
StandaloneWSResponse

Deprecated methods

Attributes

Deprecated
true

Inherited methods

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

Inherited from:
StandaloneWSResponse

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 akka.util.ByteString:

Converts a response body into an akka.util.ByteString:

import akka.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 readableAsJson: BodyReadable[JsValue]

Converts a response body into Play JSON format:

Converts a response body into Play JSON format:

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

def json(r: StandaloneWSResponse) = r.body[play.api.libs.json.JsValue]

Attributes

Inherited from:
JsonBodyReadables
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
implicit val readableAsXml: BodyReadable[Elem]

Converts a response body into XML document:

Converts a response body into XML document:

import scala.xml.Elem

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

def foo(resp: StandaloneWSResponse): Elem = resp.body[Elem]

Attributes

Inherited from:
XMLBodyReadables