Skip to content

Instance Method

encode(_:boundary:to:)

Encodes an Encodable item into some MultipartPartBodyElement using the supplied boundary.
func encode<E, Body>(_ encodable: E, boundary: String, to: Body.Type = Body.self) throws -> Body where E : Encodable, Body : RangeReplaceableCollection, Body : Sendable, Body.Element == UInt8

Parameters

encodable

Generic Encodable item.

boundary

Multipart boundary to use for encoding. This must not appear anywhere in the encoded data.

to

Buffer to write to.

Discussion

let a = Foo(string: "a", int: 42, double: 3.14, array: [1, 2, 3])
var buffer = ByteBuffer()
let data = try FormDataEncoder().encode(a, boundary: "123", into: &buffer)

Throws

Any errors encoding the model with Codable or serializing the data.