Body

zio.http.Body
See theBody companion object
trait Body

Represents the body of a request or response. The body can be a fixed chunk of bytes, a stream of bytes, or form data, or any type that can be encoded into such representations (such as textual data using some character encoding, the contents of files, JSON, etc.).

Attributes

Companion
object
Source
Body.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Abstract methods

def asArray(implicit trace: Trace): Task[Array[Byte]]

Returns an effect that decodes the content of the body as array of bytes. Note that attempting to decode a large stream of bytes into an array could result in an out of memory error.

Returns an effect that decodes the content of the body as array of bytes. Note that attempting to decode a large stream of bytes into an array could result in an out of memory error.

Attributes

Source
Body.scala
def asChunk(implicit trace: Trace): Task[Chunk[Byte]]

Returns an effect that decodes the content of the body as a chunk of bytes. Note that attempting to decode a large stream of bytes into a chunk could result in an out of memory error.

Returns an effect that decodes the content of the body as a chunk of bytes. Note that attempting to decode a large stream of bytes into a chunk could result in an out of memory error.

Attributes

Source
Body.scala
def asStream(implicit trace: Trace): ZStream[Any, Throwable, Byte]

Returns a stream that contains the bytes of the body. This method is safe to use with large bodies, because the elements of the returned stream are lazily produced from the body.

Returns a stream that contains the bytes of the body. This method is safe to use with large bodies, because the elements of the returned stream are lazily produced from the body.

Attributes

Source
Body.scala

Attributes

Source
Body.scala
def contentType(newContentType: ContentType): Body

Attributes

Source
Body.scala

Returns whether or not the bytes of the body have been fully read.

Returns whether or not the bytes of the body have been fully read.

Attributes

Source
Body.scala

Returns whether or not the body is known to be empty. Note that some bodies may not be known to be empty until an attempt is made to consume them.

Returns whether or not the body is known to be empty. Note that some bodies may not be known to be empty until an attempt is made to consume them.

Attributes

Source
Body.scala

Returns whether or not the content length is known

Returns whether or not the content length is known

Attributes

Source
Body.scala

Concrete methods

def ++(that: Body): Body

A right-biased way of combining two bodies. If either body is empty, the other will be returned. Otherwise, the right body will be returned.

A right-biased way of combining two bodies. If either body is empty, the other will be returned. Otherwise, the right body will be returned.

Attributes

Source
Body.scala
def asForm[A](implicit schema: Schema[A], trace: Trace): Task[A]

Decodes the content of the body as a URL-encoded form and maps it to a case class using a zio-schema zio.schema.Schema.

Decodes the content of the body as a URL-encoded form and maps it to a case class using a zio-schema zio.schema.Schema.

Example:

case class Login(username: String, password: String)
implicit val schema: Schema[Login] = DeriveSchema.gen[Login]
val body = Body.fromString("username=john&password=secret")
 .contentType(MediaType.application.`x-www-form-urlencoded`)
val login: Task[Login] = body.asForm[Login]

Attributes

Source
Body.scala
def asJson[A](implicit schema: Schema[A], trace: Trace): Task[A]

Decodes the content of the body as JSON using zio-schema.

Decodes the content of the body as JSON using zio-schema.

Example:

import zio.schema.{DeriveSchema, Schema}
case class Person(name: String, age: Int)
implicit val schema: Schema[Person] = DeriveSchema.gen[Person]
val body = ???
val decodedPerson: Task[Person] = body.asJson[Person]

Attributes

Source
Body.scala
def asJsonFromCodec[A](implicit decoder: JsonDecoder[A], trace: Trace): Task[A]

Decodes the content of the body as JSON using zio-json.

Decodes the content of the body as JSON using zio-json.

Example:

import zio.json._
case class Person(name: String, age: Int)
implicit val decoder: JsonDecoder[Person] = DeriveJsonDecoder.gen[Person]
val body = ???
val decodedPerson: Task[Person] = body.asJsonZio[Person]

Attributes

Source
Body.scala
def asMultipartForm(implicit trace: Trace): Task[Form]

Returns an effect that decodes the content of the body as a multipart form. Note that attempting to decode a large stream of bytes into a form could result in an out of memory error.

Returns an effect that decodes the content of the body as a multipart form. Note that attempting to decode a large stream of bytes into a form could result in an out of memory error.

Attributes

Source
Body.scala

Returns an effect that decodes the streaming body as a multipart form.

Returns an effect that decodes the streaming body as a multipart form.

The result is a stream of FormField objects, where each FormField may be a StreamingBinary or a Text object. The StreamingBinary object contains a stream of bytes, which has to be consumed asynchronously by the user to get the next FormField from the stream.

Attributes

Source
Body.scala
def asMultipartMixed(implicit trace: Trace): Task[MultipartMixed]

Returns an effect that decodes the streaming body as a multipart/mixed.

Returns an effect that decodes the streaming body as a multipart/mixed.

The result is a stream of Part objects, where each Part has headers and contents (binary stream), Part objects can be easily converted to a Body objects which provide vast API for extracting their contents.

Attributes

Source
Body.scala
def asServerSentEvents[T : Schema](implicit evidence$1: Schema[T], trace: Trace): ZStream[Any, Throwable, ServerSentEvent[T]]

Attributes

Source
Body.scala
final def asString(implicit trace: Trace): Task[String]

Decodes the content of the body as a string with the default charset. Note that attempting to decode a large stream of bytes into a string could result in an out of memory error.

Decodes the content of the body as a string with the default charset. Note that attempting to decode a large stream of bytes into a string could result in an out of memory error.

Attributes

Source
Body.scala
final def asString(charset: Charset)(implicit trace: Trace): Task[String]

Decodes the content of the body as a string with the provided charset. Note that attempting to decode a large stream of bytes into a string could result in an out of memory error.

Decodes the content of the body as a string with the provided charset. Note that attempting to decode a large stream of bytes into a string could result in an out of memory error.

Attributes

Source
Body.scala
def asURLEncodedForm(implicit trace: Trace): Task[Form]

Returns an effect that decodes the content of the body as form data.

Returns an effect that decodes the content of the body as form data.

Attributes

Source
Body.scala
final def contentType(newMediaType: MediaType): Body

Updates the media type attached to this body, returning a new Body with the updated media type

Updates the media type attached to this body, returning a new Body with the updated media type

Attributes

Source
Body.scala
final def contentType(newMediaType: MediaType, newBoundary: Boundary): Body

Attributes

Source
Body.scala
def materialize(implicit trace: Trace): UIO[Body]

Materializes the body of the request into memory

Materializes the body of the request into memory

Attributes

Source
Body.scala

Returns the materialized content as a string if it's already in memory. Uses the charset from contentType if available, otherwise uses HTTP charset. Streaming and file bodies return None as they are not materialized.

Returns the materialized content as a string if it's already in memory. Uses the charset from contentType if available, otherwise uses HTTP charset. Streaming and file bodies return None as they are not materialized.

Attributes

Source
Body.scala

Returns the materialized content of the body if it's already in memory. Streaming and file bodies return None as they are not materialized.

Returns the materialized content of the body if it's already in memory. Streaming and file bodies return None as they are not materialized.

Attributes

Source
Body.scala
final def mediaType: Option[MediaType]

Returns the media type for this Body

Returns the media type for this Body

Attributes

Source
Body.scala
def to[A](implicit codec: BinaryCodec[A], trace: Trace): Task[A]

Decodes the content of the body as a value based on a zio-schema zio.schema.codec.BinaryCodec.

Decodes the content of the body as a value based on a zio-schema zio.schema.codec.BinaryCodec.

Example for json:

import zio.schema.json.codec._
case class Person(name: String, age: Int)
implicit val schema: Schema[Person] = DeriveSchema.gen[Person]
val person = Person("John", 42)
val body = ???
val decodedPerson = body.to[Person]

Attributes

Source
Body.scala