How to make simple networking client in Swift

Issue #222 For more mature networking, visit https://github.com/onmyway133/Miami final class NetworkClient { let session: URLSession let baseUrl: URL init(session: URLSession = .shared, baseUrl: URL) { self.session = session self.baseUrl = baseUrl } func make(options: Options, completion: @escaping (Result<Data, Error>) -> Void) { guard let request = options.toRequest(baseUrl: baseUrl) else { completion(.failure(AppError.request)) return } let task = session.dataTask(with: request, completionHandler: { data, _, error in if let data = data { completion(....

May 2, 2019 · 2 min · 290 words · Khoa