StreamedResponse

play.api.libs.ws.ahc.StreamedResponse
class StreamedResponse(client: StandaloneAhcWSClient, val status: Int, val statusText: String, val uri: URI, val headers: Map[String, Seq[String]], publisher: Publisher[HttpResponseBodyPart], val useLaxCookieEncoder: Boolean) extends StandaloneWSResponse, CookieBuilder

A streamed response containing a response header and a streamable body.

Note that this is only usable with a stream call, i.e.

import scala.concurrent.{ ExecutionContext, Future }

import org.apache.pekko.util.ByteString
import org.apache.pekko.stream.scaladsl.Source

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

class MyClass(ws: StandaloneAhcWSClient) {
 def doIt(implicit ec: ExecutionContext): Future[String] =
   ws.url("http://example.com").stream().map { response =>
      val _ = response.body[Source[ByteString, _]]
      ??? // process source to String
   }
}

Attributes

Graph
Supertypes
trait StandaloneWSResponse
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def underlying[T]: T

Get the underlying response object.

Get the underlying response object.

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 buildCookies(headers: Map[String, Seq[String]]): Seq[WSCookie]

Attributes

Inherited from:
CookieBuilder
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

Concrete fields

lazy override val body: String

THIS IS A BLOCKING OPERATION. It should not be used in production.

THIS IS A BLOCKING OPERATION. It should not be used in production.

Note that this is not a charset aware operation, as the stream does not have access to the underlying machinery that disambiguates responses.

Attributes

Returns

the body as a String

lazy override val bodyAsBytes: ByteString

THIS IS A BLOCKING OPERATION. It should not be used in production.

THIS IS A BLOCKING OPERATION. It should not be used in production.

Note that this is not a charset aware operation, as the stream does not have access to the underlying machinery that disambiguates responses.

Attributes

Returns

the body as a ByteString

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

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

Returns the current headers for this response.

Returns the current headers for this response.

Attributes

val status: Int

The response status code.

The response status code.

Attributes

val statusText: String

The response status message.

The response status message.

Attributes

val 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

val useLaxCookieEncoder: Boolean