Vapor Documentation

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.

%125 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(byte​Buffer​Allocator:​)

public init(byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator())  

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

init(data:​byte​Buffer​Allocator:​)

public init(data: Data, byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator())  

Create a new body wrapping Data.

init(dispatch​Data:​byte​Buffer​Allocator:​)

public init(dispatchData: DispatchData, byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator())  

Create a new body wrapping DispatchData.

init(static​String:​byte​Buffer​Allocator:​)

public init(staticString: StaticString, byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator())  

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

init(string:​byte​Buffer​Allocator:​)

public init(string: String, byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator())  

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

init(buffer:​byte​Buffer​Allocator:​)

public init(buffer: ByteBuffer, byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator())  

Create a new body from a Swift NIO ByteBuffer.

init(stream:​count:​byte​Buffer​Allocator:​)

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

init(stream:​byte​Buffer​Allocator:​)

public init(stream: @escaping (BodyStreamWriter) -> (), byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator())  

init(string​Literal:​)

public init(stringLiteral value: String)  

ExpressibleByStringLiteral conformance.

Properties

empty

public static let empty: Body  

An empty Response.Body.

string

public var string: String?  

count

public var count: Int  

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

data

public var data: Data?  

Returns static data if not streaming.

buffer

public var buffer: ByteBuffer?  

description

public var description: String  

See CustomDebugStringConvertible.

Methods

collect(on:​)

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