OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why does restcountries API does not work while my JavaScript code is correct

  • Thread starter Thread starter dushimimana fabrice
  • Start date Start date
D

dushimimana fabrice

Guest
I'm trying to get data about countries using Rest Countries API by using link which is inside GitHub repository https://github.com/public-apis/public-apis. And when I open this API This is what I get:

{"message":"Page Not Found","_links":{"self":{"href":"/","templated":false}}}.

And this is my JavaScript code:

Code:
  const getCountryData = function (country) {
  const request = new XMLHttpRequest();
  request.open('GET', `https://restcountries.eu/rest/v2/name/${country}`);
  request.send();
  request.addEventListener('load', function () {
    console.log(this.responseText);
  });
};

getCountryData('rwanda');
getCountryData('brazil');

Why is this happening?

<p>I'm trying to get data about countries using <strong>Rest Countries API</strong> by using link which is inside GitHub repository <a href="https://github.com/public-apis/public-apis" rel="nofollow noreferrer">https://github.com/public-apis/public-apis</a>.
And when I open this API This is what I get:</p>
<blockquote>
<p><strong>{"message":"Page Not Found","_links":{"self":{"href":"/","templated":false}}}</strong>.</p>
</blockquote>
<p>And this is my JavaScript code:</p>
<pre><code> const getCountryData = function (country) {
const request = new XMLHttpRequest();
request.open('GET', `https://restcountries.eu/rest/v2/name/${country}`);
request.send();
request.addEventListener('load', function () {
console.log(this.responseText);
});
};

getCountryData('rwanda');
getCountryData('brazil');
</code></pre>
<p>Why is this happening?</p>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top