Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simrandotdev/de404ce7e43a038930f0518079080a9d to your computer and use it in GitHub Desktop.
Save simrandotdev/de404ce7e43a038930f0518079080a9d to your computer and use it in GitHub Desktop.
import UIKit
import Foundation
func loadData() {
do {
guard let url = URL(string: "https://reqres.in/api/users/1") else { return }
var request = URLRequest(url: url)
request.httpMethod = "DELETE"
URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error {
print("Something went wrong with the request: \(error.localizedDescription)")
return
}
guard let _ = data else {
print("No data found.")
return
}
guard let httpResponse = response as? HTTPURLResponse else {
return
}
print("\(httpResponse.statusCode)")
}.resume()
} catch let error {
print(error.localizedDescription)
}
}
loadData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment