FormDataEncoder

public final class FormDataEncoder

Encodes Encodable items to multipart/form-data encoded Data.

See RFC#2388 for more information about multipart/form-data encoding.

Seealso MultipartParser for more information about the multipart encoding.

  • Creates a new FormDataEncoder.

    Declaration

    Swift

    public init()
  • Encodes an Encodable item to Data using the supplied boundary.

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

    Throws

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

    Declaration

    Swift

    public func encode<E>(_ encodable: E, boundary: LosslessDataConvertible) throws -> Data where E: Encodable

    Parameters

    encodable

    Generic Encodable item.

    boundary

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

    Return Value

    multipart/form-data-encoded Data.