Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

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 type to write to.

Discussion

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

Throws

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