0

I have an input string that contains a partial URL such as "wikipedia.org" and I want to get the full URL "https://www.wikipedia.org/" using Node or JavaScript. Is there a standard way to do this?

The problem is not knowing if the URL is HTTP or https and I would rather not make two API calls to test each case.

Hasan Aga
  • 718
  • 8
  • 27
  • 2
    You can probably just use HTTP as most websites will redirect the HTTP to HTTPS – CootMoon Feb 05 '23 at 18:45
  • 1
    There is no standard way to do this. If you just type `wikipedia.org` into the browser, it will make a guess as to whether to use http or https and try that. The guess may or may not be influenced by what's in your history. I think it will generally try `http` first and like has already been said, most sites will then redirect to https. – jfriend00 Feb 05 '23 at 18:57
  • 2
    Converting `wikipedia.org` to `www.wikipedia.org` is usually handled by wikipedia as a redirect. Deciding whether to use `http:` or `https:` is decided by the browser, usually based on prior knowledge (it remembers that you've visited the site before) or defaults (used to be `http`, but these days is usually `https`). Note that these are all for user convenience and aren't required or spelled out by any spec. – Ouroborus Feb 05 '23 at 19:04

1 Answers1

1

That problem can be solved by calling a specific API that provides SSL Verify checks.

As an example you can use rapidapi.

const axios = require("axios");

const options = {
  method: 'POST',
  url: 'https://ssl-certificate-checker.p.rapidapi.com/ssl-certificate',
  headers: {
    'content-type': 'application/json',
    'X-RapidAPI-Key': '9a02e1bd8emsh83423276ecdc759p153572jsn874d28bed296',
    'X-RapidAPI-Host': 'ssl-certificate-checker.p.rapidapi.com'
  },
  data: '{"port":"443","url":"wikipedia.org"}'
};

axios.request(options).then(function (response) {
    console.log(response.data);
}).catch(function (error) {
    console.error(error);
});

For details you can check the site of the API.

Click here to check articles and solutions to similar questions.

  • @HasanAga Note that that end-point is limited to 10 requests/day with a pay option for more than that. The API key should be your rapidapi API key. – Ouroborus Feb 05 '23 at 19:14
  • For questions that are duplicates of older questions, instead of answering them, you close them as a duplicate (it requires that you link to the older question and will show this in the close reason, visible to the asker and to users with enough points). If the answers to the older question lacks information you want to include, you edit or add your answer to the older question. – Ouroborus Feb 05 '23 at 19:21