URLSessionNetworkHandler

public class URLSessionNetworkHandler<Encoder: TopLevelEncoder, Decoder: TopLevelDecoder>: NetworkHandler
where Encoder.Output == Data, Decoder.Input == Data

URLSessionNetworkHandler conforms to the NetworkHandler protocol and represents an implementation of the different network requests

  • specifies the encoding strategy

    Declaration

    Swift

    public let encoder: Encoder
  • specifies the decoding strategy

    Declaration

    Swift

    public let decoder: Decoder
  • specifies the authorization method

    Declaration

    Swift

    public let authorization: Authorization
  • initialization of the URLSessionNetworkHandler with .none as default Authorization variable

    Declaration

    Swift

    public init(encoder: Encoder, decoder: Decoder, authorization: Authorization = .none)
  • performs a PUT request on the specified URL and replaces the element located on the URL with the Element that is passed in

    Declaration

    Swift

    public func put<Element>(_ element: Element, on route: URL) -> AnyPublisher<Element, Error> where Element : Decodable, Element : Encodable

    Parameters

    element

    the element that is used to replace the old element

    route

    the URL where the old element is located

    Return Value

    an AnyPublisher that holds the new Element and an Error

  • performs a GET request on the specified URL

    Declaration

    Swift

    public func get<Element>(on route: URL) -> AnyPublisher<[Element], Error> where Element : Decodable, Element : Encodable

    Parameters

    route

    the URL where the GET request gets the Elements

    Return Value

    an AnyPublisher that holds the returned array of Elements and an Error

  • performs a POST request on the specified URL

    Declaration

    Swift

    public func post<Element>(_ element: Element, on route: URL) -> AnyPublisher<Element, Error> where Element : Decodable, Element : Encodable

    Parameters

    element

    the new Element that is posted

    route

    the URL for the new Element

    Return Value

    an AnyPublisher that holds the new Element and an Error

  • performs a DELETE request on the specified URL

    Declaration

    Swift

    public func delete(at route: URL) -> AnyPublisher<Void, Error>

    Parameters

    route

    the URL where the removal happens

    Return Value

    an AnyPublisher that holds a Void type and an Error