Structure
Response.Body
Represents a
Response’s body.struct Body
Overview
let body = Response.Body(string: "Hello, world!")
This can contain any data (streaming or static) and should match the message’s "Content-Type" header.
Topics
Initializers
init(asyncStream: (any AsyncBodyStreamWriter) async throws -> (), byteBufferAllocator: ByteBufferAllocator)Creates a chunked HTTPResponsesteam usingAsyncBodyStreamWriter.init(asyncStream: (any AsyncBodyStreamWriter) async throws -> (), count: Int, byteBufferAllocator: ByteBufferAllocator)Creates a chunked HTTPResponsesteam usingAsyncBodyStreamWriter.init(buffer: ByteBuffer, byteBufferAllocator: ByteBufferAllocator)Create a new body from a Swift NIOByteBuffer.init(byteBufferAllocator: ByteBufferAllocator)Creates an empty body. Useful forGETrequests where HTTP bodies are forbidden.init(data: Data, byteBufferAllocator: ByteBufferAllocator)Create a new body wrappingData.init(dispatchData: DispatchData, byteBufferAllocator: ByteBufferAllocator)Create a new body wrappingDispatchData.init(managedAsyncStream: (any AsyncBodyStreamWriter) async throws -> (), byteBufferAllocator: ByteBufferAllocator)Creates a managed chunked HTTPResponsesteam usingAsyncBodyStreamWriterthat automtically closes or fails based if the closure throws an error or returns.init(managedAsyncStream: (any AsyncBodyStreamWriter) async throws -> (), count: Int, byteBufferAllocator: ByteBufferAllocator)Creates a managed chunked HTTPResponsesteam usingAsyncBodyStreamWriterthat automtically closes or fails based if the closure throws an error or returns.init(staticString: StaticString, byteBufferAllocator: ByteBufferAllocator)Create a new body from the UTF8 representation of aStaticString.init(stream: (any BodyStreamWriter) -> (), byteBufferAllocator: ByteBufferAllocator)init(stream: (any BodyStreamWriter) -> (), count: Int, byteBufferAllocator: ByteBufferAllocator)init(string: String, byteBufferAllocator: ByteBufferAllocator)Create a new body from the UTF8 representation of aString.init(stringLiteral: String)ExpressibleByStringLiteralconformance.
Instance Properties
var buffer: ByteBuffer?var count: IntThe size of the HTTP body’s data.-1is a chunked stream.var data: Data?Returns static data if not streaming.var description: StringSeeCustomDebugStringConvertible.var string: String?
Instance Methods
Type Properties
static let empty: Response.BodyAn emptyResponse.Body.
Relationships
Conforms To
Swift.CustomStringConvertibleSwift.ExpressibleByExtendedGraphemeClusterLiteralSwift.ExpressibleByStringLiteralSwift.ExpressibleByUnicodeScalarLiteralSwift.SendableSwift.SendableMetatype