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
JSONEncodinginstance with default writing options.Declaration
Swift
public static var `default`: JSONEncoding { get } -
Returns a
JSONEncodinginstance with.prettyPrintedwriting options.Declaration
Swift
public static var prettyPrinted: JSONEncoding { get } -
The options for writing the parameters as JSON data.
Declaration
Swift
public let options: JSONSerialization.WritingOptions
-
Creates a
JSONEncodinginstance using the specified options.Declaration
Swift
public init(options: JSONSerialization.WritingOptions = [])Parameters
optionsThe options for writing the parameters as JSON data.
Return Value
The new
JSONEncodinginstance.
-
Creates a URL request by encoding parameters and applying them onto an existing request.
Throws
An
Errorif the encoding process encounters an error.Declaration
Swift
public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequestParameters
urlRequestThe request to have parameters applied.
parametersThe parameters to apply.
Return Value
The encoded request.
-
Creates a URL request by encoding the JSON object and setting the resulting data on the HTTP body.
Throws
An
Errorif the encoding process encounters an error.Declaration
Swift
public func encode(_ urlRequest: URLRequestConvertible, withJSONObject jsonObject: Any? = nil) throws -> URLRequestParameters
urlRequestThe request to apply the JSON object to.
jsonObjectThe JSON object to apply to the request.
Return Value
The encoded request.
View on GitHub
Install in Dash
JSONEncoding Structure Reference