I tried to use it by using the example codes but I don't know why it's not working... I want to use anilist Api using axios in JavaScript but docs is not easy to understand.... (https://anilist.gitbook.io/anilist-apiv2-docs/overview/graphql/getting-started)
Here Example Code:
var query = `
query ($id: Int) { # Define which variables will be used in the query (id)
Media (id: $id, type: ANIME) { # Insert our variables into the query arguments (id) (type: ANIME is hard-coded in the query)
id
title {
romaji
english
native
}
}
}
`;
var variables = {
id: 15125
};
var url = 'https://graphql.anilist.co',
options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: query,
variables: variables
})
};
fetch(url, options).then(handleResponse)
.then(handleData)
.catch(handleError);
function handleResponse(response) {
return response.json().then(function (json) {
return response.ok ? json : Promise.reject(json);
});
}
function handleData(data) {
console.log(data);
}
function handleError(error) {
alert('Error, check console');
console.error(error);
}
I want to fetch it so I can get data easily inside console.log(data) can anyone please explain or help how to use it?