Vapor Documentation Beta

Structure Response.​Body

public struct Body: CustomStringConvertible, ExpressibleByStringLiteral

Represents a Response's body.

let body = Response.Body(string: "Hello, world!")

This can contain any data (streaming or static) and should match the message's "Content-Type" header.

%3 Response.Body Response.Body ExpressibleByStringLiteral ExpressibleByStringLiteral Response.Body->ExpressibleByStringLiteral CustomStringConvertible CustomStringConvertible Response.Body->CustomStringConvertible

Member Of

Response

An HTTP response from a server back to the client.

Conforms To

CustomStringConvertible
ExpressibleByStringLiteral

Initializers

init()

public init()

Creates an empty body. Useful for GET requests where HTTP bodies are forbidden.

init(data:​)

public init(data: Data)

Create a new body wrapping Data.

init(dispatch​Data:​)

public init(dispatchData: DispatchData)

Create a new body wrapping DispatchData.

init(static​String:​)

public init(staticString: StaticString)

Create a new body from the UTF8 representation of a StaticString.

init(string:​)

public init(string: String)

Create a new body from the UTF8 representation of a String.

init(buffer:​)

public init(buffer: ByteBuffer)

Create a new body from a Swift NIO ByteBuffer.

init(stream:​count:​)

public init(stream: @escaping (BodyStreamWriter) -> (), count: Int)

init(stream:​)

public init(stream: @escaping (BodyStreamWriter) -> ())

init(string​Literal:​)

public init(stringLiteral value: String)

ExpressibleByStringLiteral conformance.

Properties

empty

let empty: Body

An empty Response.Body.

string

var string: String?

count

var count: Int

The size of the HTTP body's data. -1 is a chunked stream.

data

var data: Data?

Returns static data if not streaming.

buffer

var buffer: ByteBuffer?

description

var description: String

See CustomDebugStringConvertible.

Methods

collect(on:​)

public func collect(on eventLoop: EventLoop) -> EventLoopFuture<ByteBuffer?>