You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
URLs are extended to GET, POST, PUT, and DELETE. You can call these methods directly but using RestHelper will take care of the model encoding and decoding. The easiest way to make REST calls is to extend DataService as shown above.
Get an image from URL (call back on Main Thread).
url.getImage { image in
if let image = image {
imageView.image = image
} else {
imageView.image = UIImage(named: "ImageNotFound")
}
}
Get a Codable model from URL.
url.getModel(type: Pet.self) { pet in
print(pet)
}
Get N models from from a list of URLs in parallel, return when all model requests are completed.
let url1 = "http://localhost:3000/pets/100"
let url2 = "http://localhost:3000/pets/200"
let url3 = "http://localhost:3000/pets/300"
[url1, url2, url3].get { data in
let pets: [Pet] = data.compactMap { $0.decode() }
print(pets)
}