static func getUsers(completionHandler: @escaping (_ users: [User]?, _ error: Error?) -> Void) { let endpointUrl = URL(string: host + listUsersPath)! let urlRequest = URLRequest(url: endpointUrl) let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in guard error == nil else { print("error calling GET on \(listUsersPath): \(error!)") DispatchQueue.main.async { completionHandler(nil, error) } return } let usersData = try! JSONSerialization.jsonObject(with: data!, options: []) as! [Any] var users = [User]() for userData in usersData { let userDict = userData as! Dictionary let name = userDict["name"] as! String let id = userDict["id"] as! Double let user = User(id: id, name: name) users.append(user) } DispatchQueue.main.async { completionHandler(users, nil) } } task.resume() }