Skip to content

Backend API Follower & Friends

Leah Copeland edited this page Apr 1, 2021 · 3 revisions

Friend & Follower & Friend Request

/service/author/{AUTHOR_ID}/followers/ to retrieve a list of authors who are their followers

  • Request method: GET
  • example response:
{
    # type of item in the items
    "type": "followers",      
    # list of followers
    "items":[
        {
            "type":"author",
            "id":"http://127.0.0.1:5454/author/1d698d25ff008f7538453c120f581471",
            "displayName":"Greg Johnson",
            "github": "http://github.com/gjohnson"
        },
        {
            "type":"author",
            "id":"http://127.0.0.1:5454/author/9de17f29c12e8f97bcbbd34cc908f1baba40658e",
            "displayName":"Lara Croft",
            "github": "http://github.com/laracroft"
        }
    ]
}
  • response status code:
    • 200: OK
    • 404: no followers found or incorrect id of author

/service/author/{AUTHOR_ID}/followers/{FOREIGN_AUTHOR_ID}/ to remove a follower/friend, add a follower/friend, or check if is follower (requires logged in)

  • Request method: PUT, DELETE, GET
  • Note:
    • if {FOREIGN_AUTHOR_ID} already followed {AUTHOR_ID}, PUT will be equivalent to {AUTHOR_ID} befriend and follow {FOREIGN_AUTHOR_ID}
    • if {AUTHOR_ID} and {FOREIGN_AUTHOR_ID} are friend, DELETE will be equivalent to {AUTHOR_ID} unfriend and unfollow {FOREIGN_AUTHOR_ID}
  • example response:
{
    "message": "success",
}
  • response status code:
    • 200: success, added as friends and followers
    • 200: unfollow and unfriend success
    • 200: success
    • 200: unfollow success
    • 404: author has no followers or incorrect id of author
    • 404: foreign id is not a follower
    • 404: invalid foreign id
    • 405: method not allowed
    • 400: author id and foreign author id are the same

/service/author/{AUTHOR_ID}/friends/ to retrieve a list of authors who are their friends

  • Request method: GET
  • example response:
{
    # type of item in the items
    "type": "friend",      
    # list of friends
    "items":[
        {
            "type":"author",
            "id":"http://127.0.0.1:5454/author/1d698d25ff008f7538453c120f581471",
            "displayName":"Greg Johnson",
            "github": "http://github.com/gjohnson"
        },
        {
            "type":"author",
            "id":"http://127.0.0.1:5454/author/9de17f29c12e8f97bcbbd34cc908f1baba40658e",
            "displayName":"Lara Croft",
            "github": "http://github.com/laracroft"
        }
    ]
}
  • response status code:
    • 200: OK
    • 404: no followers found or incorrect id of author
    • 405: method not allowed

/service/author/{AUTHOR_ID}/friends/{FOREIGN_AUTHOR_ID}/ to check if foreign_author_id is friend with author_id

  • Request method: GET, PUT
  • example response:
{
    # type of item in the items
    "message": "success",      
}
  • response status code:
    • 200: success
    • 404: author has no friends or incorrect id of author
    • 404: foreign id is not a follower
    • 404: invalid foreign id
    • 405: actor id is not in any existing sharing node. Contact admin server to add your node to our server
    • 400: author id and foreign author id are the same

/service/author/{AUTHOR_ID}/nonfollowers/ to retrieve a list of authors who are not their followers or friends (requires logged in)

  • Request method: GET
  • example response:
{
    # type of item in the items
    "type": "nonfollower",      
    # list of followers
    "items":[
        {
            "type":"author",
            "id":"http://127.0.0.1:5454/author/1d698d25ff008f7538453c120f581471",
            "displayName":"Greg Johnson",
            "github": "http://github.com/gjohnson"
        },
        {
            "type":"author",
            "id":"http://127.0.0.1:5454/author/9de17f29c12e8f97bcbbd34cc908f1baba40658e",
            "displayName":"Lara Croft",
            "github": "http://github.com/laracroft"
        }
    ]
}
  • response status code:
    • 200: OK
    • 404: no non-followers found
    • 405: method not allowed

/service/author/{AUTHOR_ID}/follower_remote_18/{FOREIGN_AUTHOR_ID}/{TEAM_18_HOST} To Follow a team 18 user

  • Request method: GET
if request.method == 'GET':
        url = team_18_host + "service/author/" + str(author_id) + "/inbox/"
        body = { "type": "follow", "new_follower_ID": foreign_author_id} 
        response = requests.post(url, data = body)
        result = response.json()
        response = JsonResponse({"message from team 18's response": result})
        response.status_code = 200
        return response

Clone this wiki locally