StreamedResponse
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 CookieBuildertrait WSCookieConvertertrait StandaloneWSResponseclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Get only one cookie, using the cookie name.
Get only one cookie, using the cookie name.
Attributes
- Definition Classes
-
StandaloneWSResponse
Get the underlying response object.
Get the underlying response object.
Attributes
- Definition Classes
-
StandaloneWSResponse
Inherited methods
Attributes
- Inherited from:
- WSCookieConverter
Attributes
- Inherited from:
- WSCookieConverter
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
Attributes
- Inherited from:
- CookieBuilder
Attributes
- Returns
-
the content type.
- Inherited from:
- StandaloneWSResponse
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
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
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
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
Attributes
- Returns
-
the response as a source of bytes
Get all the cookies.
Get all the cookies.
Attributes
Returns the current headers for this response.
Returns the current headers for this response.
Attributes
The response status code.
The response status code.
Attributes
The response status message.
The response status message.
Attributes
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.