Json

public struct Json<T> : HttpBody where T : Encodable

The JSON HTTP body is presumably the most commonly used non-empty body for HTTP requests. It encodes an encodable type as JSON and sets the body of an HTTP request as well as the “Content-Type” header to “application/json”.

Initialization

  • Initializes a new JSON HTTP body which ought to encode the given value in the request body.

    Declaration

    Swift

    public init(_ value: T, encoder: JSONEncoder? = nil)

    Parameters

    value

    The value to put into the request body.

    encoder

    The JSON encoder to use for encoding. When set to nil, a JSON encoder is used where camel case attribute names are converted into snake case.

HttpBody

  • Declaration

    Swift

    public func add(to request: inout URLRequest) throws

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }