Validate a Domain in Swift

As we have discussed in our other articles, phishing attempts and cyber-attacks are happening at an increasingly alarming rate . To protect your organization and clients from these threats, you have to stay ahead of the game by developing a solid security plan. Incorporating the plan into your everyday business will reassure your internal and external partners that you can be trusted with their sensitive or confidential data. Utilizing the following API in Swift is an easy way to automatically validate a domain name and ensure it doesn’t hold malicious intent.

Now, all you need to do is plug in your domain name and API key into the following code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)let parameters = "\"<string>\""
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.cloudmersive.com/validate/domain/check")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()

The API does a quick connect with DNS Services to perform the validation and instantly delivers the result. To retrieve your API key, head to the Cloudmersive website to register for a free account; this will give you access to 800 monthly calls across hundreds of APIs!

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.