Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. function getCharacter(id, callback) {
  2. var query = `
  3. query($id: Int) {
  4. Character (id: $id) {
  5. id
  6. image {
  7. large
  8. }
  9. name {
  10. first
  11. last
  12. }
  13. }
  14. }
  15. `;
  16. var variables = {
  17. id: id
  18. };
  19. var url = 'https://graphql.anilist.co',
  20. options = {
  21. method: 'POST',
  22. headers: {
  23. 'Content-Type': 'application/json',
  24. 'Accept': 'application/json',
  25. },
  26. body: JSON.stringify({
  27. query: query,
  28. variables: variables
  29. })
  30. };
  31. fetch(url, options).then(handleResponse)
  32. .then(function(response) {
  33. callback(response.data.Character);
  34. })
  35. .catch(function(err) {
  36. handleError(err)
  37. callback(null);
  38. });
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement