JSONEncoding

public struct JSONEncoding: ParameterEncoding

Uses JSONSerialization to create a JSON representation of the parameters object, which is set as the body of the request. The Content-Type HTTP header field of an encoded request is set to application/json.

  • Returns a JSONEncoding instance with default writing options.

    Declaration

    Swift

    public static var `default`: JSONEncoding
  • Returns a JSONEncoding instance with .prettyPrinted writing options.

    Declaration

    Swift

    public static var prettyPrinted: JSONEncoding
  • The options for writing the parameters as JSON data.

    Declaration

    Swift

    public let options: JSONSerialization.WritingOptions
  • Creates a JSONEncoding instance using the specified options.

    Declaration

    Swift

    public init(options: JSONSerialization.WritingOptions = [])
  • Creates a URL request by encoding parameters and applying them onto an existing request.

    Throws

    An Error if the encoding process encounters an error.

    Declaration

    Swift

    public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest