Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

JSONEncoding

mattt edited this page Sep 18, 2020 · 2 revisions

JSONEncoding

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.

public struct JSONEncoding:​ ParameterEncoding

Inheritance

ParameterEncoding

Initializers

init(options:​)

Creates an instance using the specified WritingOptions.

public init(options:​ JSONSerialization.WritingOptions = [])

Parameters

  • options:​ JSONSerialization.WritingOptions to use.

Properties

`default`

Returns a JSONEncoding instance with default writing options.

var `default`:​ JSONEncoding

prettyPrinted

Returns a JSONEncoding instance with .prettyPrinted writing options.

var prettyPrinted:​ JSONEncoding

options

The options for writing the parameters as JSON data.

let options:​ JSONSerialization.WritingOptions

Methods

encode(_:​with:​)

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

encode(_:​withJSONObject:​)

Encodes any JSON compatible object into a URLRequest.

public func encode(_ urlRequest:​ URLRequestConvertible, withJSONObject jsonObject:​ Any? = nil) throws -> URLRequest

Parameters

  • urlRequest:​ URLRequestConvertible value into which the object will be encoded.
  • jsonObject:​ Any value (must be JSON compatibleto be encoded into theURLRequest. nil` by default.

Throws

Any Error produced during encoding.

Returns

The encoded URLRequest.

Types
Protocols
Global Typealiases
Clone this wiki locally