I'm trying to fetch from the wikipedia api and I get the "Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource" error. I do not know if it has to do with the way I am appending params. I have no experience with that and I just googled a solution. I tested the parameters on postman so I know it's the right data.
const searchQuery = async () => {
const params = {
action: "query",
format: "json",
list: "search",
srsearch: "salvador dali",
};
const url = new URL("https://en.wikipedia.org/w/api.php/");
for (let param in params) {
url.searchParams.append(param, params[param]);
}
const searchData = await fetch(url);
console.log(searchData);
const data = await searchData.json();
console.log(data);
};