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 Friends

/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);
                }
            });
        }

Following user

"/service/author/{AUTHOR_ID}/followers/{FOREIGN_AUTHOR_ID}/ to follow a user/friend request a user

  • Request method: PUT -!important: in this instance {AUTHOR_ID} is the author the logged in user is following and {FOREIGN_AUTHOR_ID} is the current logged in users id
follow(url).done(function(response) {
                console.log(response);
            });

function follow(url){
            return $.ajax({
                url: url,
                type: 'PUT',
                contentType: "application/json",
                success: function(result) {
                    console.log(result)
                   
                }
            })
        }
'''

Clone this wiki locally