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 defaultAuthorization
variableDeclaration
Swift
public init(encoder: Encoder, decoder: Decoder, authorization: Authorization = .none)
-
performs a PUT request on the specified
URL
and replaces the element located on theURL
with theElement
that is passed inDeclaration
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 locatedReturn Value
an
AnyPublisher
that holds the newElement
and anError
-
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 theElements
Return Value
an
AnyPublisher
that holds the returned array ofElements
and anError
-
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 postedroute
the
URL
for the newElement
Return Value
an
AnyPublisher
that holds the newElement
and anError
-
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 happensReturn Value
an
AnyPublisher
that holds aVoid
type and anError