Weather by API-Ninjas

FREEMIUM
By API Ninjas Team | Updated il y a un mois | Weather
Popularity

9.8 / 10

Latency

660ms

Service Level

100%

Health Check

N/A

Back to All Discussions

Not working in javascript fetch if error showing async function

Rapid account: Rishabhrajvanshi 61103
rishabhrajvanshi61103
il y a 5 mois

async function fetchdata(){
try {
const response = await fetch(url, options);
const result = await response.text();
console.log(result);
} catch (error) {
console.error(error);
}
}

just use this instead of the given try block it will work

Rapid account: Gauravmishragm 444
gauravmishragm444 Commented il y a 2 mois

I tried few solutions but now it is saying you are not subscribed to this api. i thought this was free api.

Rapid account: Shivpujankumar 02002
shivpujankumar02002 Commented il y a 2 mois

This code is not working

Rapid account: Studentprofessional 0
studentprofessional0 Commented il y a 2 mois

function getData()
{
const options = {
method: ‘GET’,
headers:
{
‘X-RapidAPI-Key’: ‘c74d28fc95msh0643089963e26c4p13a9adjsn4e3d51df13df’,
‘X-RapidAPI-Host’: ‘weather-by-api-ninjas.p.rapidapi.com
}
};

fetch(‘https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Karachi’)
.then(response => response.json())
.then(response => console.log(response))
.catch(response => response.error(err))

}
This is coorect workable code

Rapid account: Codingfriend 1111
codingfriend1111 Commented il y a 3 mois

async function fetchData() {
const url = ‘https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Seattle’;
const options = {
method: ‘GET’,
headers: {
‘X-RapidAPI-Key’: ‘a173513e32msh17726ed826d53c8p179137jsnb02f328154f6’,
‘X-RapidAPI-Host’: ‘weather-by-api-ninjas.p.rapidapi.com
}
};

try {
const response = await fetch(url, options);
const result = await response.text();
console.log(result);
} catch (error) {
console.error(error);
}
}

fetchData();

now its working i have used it
Rapid account: Malodevarsha 7
malodevarsha7 Commented il y a 4 mois

yes,After using all this , it is still not working

Rapid account: Mahajanritin
mahajanritin Commented il y a 5 mois

const url = ‘https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Seattle’;
const options = {
method: ‘GET’,
headers: {
‘X-RapidAPI-Key’: ‘98fd28b3fdmsh8db458e9d48af2cp1f26c8jsn06daa50110eb’,
‘X-RapidAPI-Host’: ‘weather-by-api-ninjas.p.rapidapi.com
}
};

async function fetchapi(){
try {
const response = await fetch(url, options);
const result = await response.text();
console.log(result);
} catch (error) {
console.log(error);
}

}

fetchapi();

Rapid account: Dexcoder 07
dexcoder07 Commented il y a 5 mois

(async () => {
try {
const response = await fetch(url, options);
const result = await response.json();
console.log(result);
} catch (error) {
console.error(error);
}
})();

I suggest you try this code. It works for me.
Rapid account: Mohammadsaif 0847
mohammadsaif0847 Commented il y a 5 mois

try this

fetch(url, options)
.then(Response => Response.json())
.then(Response => (
console.log(Response)
))
.catch (err => console.error(err));

Rapid account: Akashsoam 123456789
akashsoam123456789 Commented il y a 5 mois

also after using this its not working.

Join in the discussion - add comment below:

Login / Signup to post new comments