JSONParameterEncoder

open class JSONParameterEncoder : @unchecked Sendable, ParameterEncoder

A ParameterEncoder that encodes types as JSON body data.

If no Content-Type header is already set on the provided URLRequests, it’s set to application/json.

  • Returns an encoder with default parameters.

    Declaration

    Swift

    public static var `default`: JSONParameterEncoder { get }
  • Returns an encoder with JSONEncoder.outputFormatting set to .prettyPrinted.

    Declaration

    Swift

    public static var prettyPrinted: JSONParameterEncoder { get }
  • Returns an encoder with JSONEncoder.outputFormatting set to .sortedKeys.

    Declaration

    Swift

    @available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *)
    public static var sortedKeys: JSONParameterEncoder { get }
  • JSONEncoder used to encode parameters.

    Declaration

    Swift

    public let encoder: JSONEncoder
  • Creates an instance with the provided JSONEncoder.

    Declaration

    Swift

    public init(encoder: JSONEncoder = JSONEncoder())

    Parameters

    encoder

    The JSONEncoder. JSONEncoder() by default.

  • Declaration

    Swift

    open func encode<Parameters: Encodable>(_ parameters: Parameters?,
                                            into request: URLRequest) throws -> URLRequest