Skip to content

AJAX Front End

Leah Copeland edited this page Mar 5, 2021 · 20 revisions

Getting Non-Followers

/service/author/{AUTHOR_ID}/nonfollowers/ to retrieve a json response containing users that the logged in user may follow/send a friend request to

  • Request method: GET

function fetchJSON(url) {
            var request = new Request(url);
            return fetch(request).then((response) => {
                if (response.status === 200 || response.status == 404) { 
                    return response.json(); // return a Promise
                } else {
                    alert("Something went wrong: " + response.status);
                }
            });
        }

Getting Followers

/service/author/{AUTHOR_ID}/followers/ to retrieve a json response containing users that are following the logged in user (sending a friend request to the logged in user)

  • Request method: GET

function fetchJSON(url) {
            var request = new Request(url);
            return fetch(request).then((response) => {
                if (response.status === 200 || response.status == 404) { 
                    return response.json(); // return a Promise
                } else {
                    alert("Something went wrong: " + response.status);
                }
            });
        }

Getting Followers

/service/author/{AUTHOR_ID}/friends/ to retrieve a json response containing users that are friends with the logged in user (both users are following each other)

  • Request method: GET

function fetchJSON(url) {
            var request = new Request(url);
            return fetch(request).then((response) => {
                if (response.status === 200 || response.status == 404) { 
                    return response.json(); // return a Promise
                } else {
                    alert("Something went wrong: " + response.status);
                }
            });
        }

Getting Friends

/service/author/{AUTHOR_ID}/friends/ to retrieve a list of users that are following the logged in user (that are friend requesting them)

  • Request method: GET

function fetchJSON(url) {
            var request = new Request(url);
            return fetch(request).then((response) => {
                if (response.status === 200 || response.status == 404) { 
                    return response.json(); // return a Promise
                } else {
                    alert("Something went wrong: " + response.status);
                }
            });
        }

Clone this wiki locally