JsonStreamRequest

public protocol JsonStreamRequest : StreamRequest where Self.Message : Encodable, Self.Result : Decodable

Similarly to the JsonRequest, this entity may be used whenever a JSON API is used, i.e. all messages being received and being sent are encoded as JSON. This requires messages to conform to the Encodable protocol as well as responses to conform to the Decodable protocol.

This entity then provides default implementations for encoding and decoding messages. Note that messages are always encoded to Data for a more efficient transmission. Messages received can be either String or Data: in both cases, they are decoded equally (note that Data messages might be more efficient.

  • decodeSnakeCase Default implementation

    Defines whether the encoder and decoder camel case in the Swift code as snake case in the JSON (i.e. userID would be encoded as/decoded from the field user_id if not specified explicity in the type to decode to). By default, attributes are encoded/decoded using snake case attribute names.

    Default Implementation

    Declaration

    Swift

    var decodeSnakeCase: Bool { get }
  • encode(_:) Extension method

    Declaration

    Swift

    public func encode(_ message: Message) throws -> URLSessionWebSocketTask.Message
  • decode(_:) Extension method

    Declaration

    Swift

    public func decode(_ message: URLSessionWebSocketTask.Message) throws -> Result