@_riteshhh
let url = URL(string: "http://api.openweathermap.org/data/2.5")!
let session = URLSession.shared
session
.dataTaskPublisher(for: url)
.validateStatusCode { (200..<300).contains($0) }
.validateResponse { !$0.data.isEmpty }
.mapErrorJson(to: ApiErrorResponse.self, decoder: decoder)
.mapValueJson(to: ApiValueResponse.self, decoder: decoder)
.sink(
receiveCompletion: { print("Completion/Failure: \($0)") },
receiveValue: { print("Value: \($0)") }
)
Declarative Networking