How to fully validate a URL in Javascript

Cloudmersive
1 min readMar 27, 2020

Today we are going to review how to use one of our APIs to fully validate URLs. This functions on multiple levels: checking syntax, existence, endpoint, and security. All of this can be achieved in just two simple steps. Here we go.

Installation comes first, requiring this script tag to be placed in your HTML file.

<script src="https://cdn.cloudmersive.com/jsclient/cloudmersive-validate-client.js"></script>

Now we can move on to calling our URL validation function.

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveValidateApiClient.DomainApi();var request = new CloudmersiveValidateApiClient.ValidateUrlRequestFull(); // ValidateUrlRequestFull | Input URL requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.domainUrlFull(request, callback);

And you’re done! You can test it out by entering in a URL to try, but that’s about all there is to it. For more like this, you may wish to look at our documentation section for a full list of validation functions available.

--

--

Cloudmersive

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