Skip to content

Instance Method

encode(_:to:headers:)

Legacy “encode object” method. The provided encodable object’s contents must be stored in the provided NIOCore/ByteBuffer, and any appropriate headers for the type of the content may be stored in the provided HTTPHeaders.
func encode<E>(_ encodable: E, to body: inout ByteBuffer, headers: inout HTTPHeaders) throws where E : Encodable

Discussion

Most encoders should implement this method by simply forwarding it to the encoder userInfo-aware version below, e.g. try self.encode(encodable, to: &body, headers: &headers, userInfo: [:]). For legacy API compatibility reasons, the default protocol conformance will do the exact opposite.