NetworkHandler
public protocol NetworkHandler
Defines a protocol to represent all the network functionality that is used to communicate with a RESTful service, the encoding/decoding strategy, the different network requests (get, post, put, delete) and the authorization method.
-
defines the encoding strategy
Declaration
Swift
associatedtype Encoder : TopLevelEncoder
-
defines the decoding strategy
Declaration
Swift
associatedtype Decoder : TopLevelDecoder
-
the variable that holds the encoder
Declaration
Swift
var encoder: Encoder { get }
-
the variable that holds the decoder
Declaration
Swift
var decoder: Decoder { get }
-
the variable that holds the authorization method
Declaration
Swift
var authorization: Authorization { get }
-
implements a GET request
Declaration
Swift
func get<Element>(on route: URL) -> AnyPublisher<[Element], Error> where Element : Decodable, Element : Encodable
Parameters
route
specifies the
URL
for the GET requestReturn Value
an
AnyPublisher
that holds a data array and an error -
implements a POST request
Declaration
Swift
func post<Element>(_ element: Element, on route: URL) -> AnyPublisher<Element, Error> where Element : Decodable, Element : Encodable
Parameters
element
specifies the element that will be posted
route
specifies the
URL
for the POST requestReturn Value
an
AnyPublisher
that holds the posted element with a specifiedID
and an error -
implements a PUT request
Declaration
Swift
func put<Element>(_ element: Element, on route: URL) -> AnyPublisher<Element, Error> where Element : Decodable, Element : Encodable
Parameters
element
specifies the new element that will be edited on the ID of this element
route
specifies the
URL
` for the PUT requestReturn Value
an
AnyPublisher
that holds the changed element and an error -
implements a DELETE request
Declaration
Swift
func delete(at route: URL) -> AnyPublisher<Void, Error>
Parameters
route
specifies the
URL
for the DELETE requestReturn Value
an
AnyPublisher
that holds an error