Skip to content

API Friend

HumphreyLu6 edited this page Sep 3, 2020 · 2 revisions

1. As an author, get my friend requests: /author/<AUTHOR_ID>/friendrequests GET

Response status code and body format:

200 OK
{
    "query": "friend requests",
    "authors": [
        "https://spongebook.herokuapp.com/author/ab187a84-7eb2-4970-9535-815311b3c874"
    ]
}

2. As an author, get my friends: /author/<AUTHOR_ID>/friends/ GET

Response status code and body format:

200 OK
{
	"query":"friends",
	"author":"<authorid>",
	# Array of Author ids
	"authors": [
	    "http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
	    "http://127.0.0.1:5454/author/ae345d54-75b4-431b-adb2-fb6b9e547891",
  	]
}

3. if anyone in the list is a friend: /author/<AUTHOR_ID>/friends POST

Request format:

{
	"query":"friends",
	"author":"<authorid>",
	# Array of Author ids
	"authors": [
	    "http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
	    "http://127.0.0.1:5454/author/ae345d54-75b4-431b-adb2-fb6b9e547891",
	    "...",
	    "...",
	    "..."
  	]
}

Response status code and body format:

200 OK
{
	"query":"friends",
 	"author":"<authorid>", # where <authorid> is the full URL of the author in question
 	# Array of Author ids who are friends
	"authors": [
	    "http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
	    "http://127.0.0.1:5454/author/ae345d54-75b4-431b-adb2-fb6b9e547891",
	    "..."
  	]
}

4. As an author, add a friend request: /friendrequest POST

Request format:

{
	"query":"friendrequest",
	"author": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Greg Johnson",
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
	},
	"friend": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e637281",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Lara Croft",
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",

	}
}

Response status code and body format:

201 Created
{

}

5. As an author, accept friend request: /friendrequest PATCH

Request format:

{
	"query":"friendrequest",
	"author": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Greg Johnson"
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
	},
	"friend": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e637281",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Lara Croft",
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",

	},
        "status":"A"
}

Response status code and body format:

200 OK
{
}

6. As an author, remove my friend: /friendrequest PATCH

Request format:

{
	"query":"friendrequest",
	"author": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Greg Johnson"
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
	},
	"friend": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e637281",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Lara Croft",
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",

	},
        "status":"R"
}

Response status code and body format:

204 No Content
{
}

7. As an author, reject friend request: /friendrequest PATCH

Request format:

{
	"query":"friendrequest",
	"author": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Greg Johnson"
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
	},
	"friend": {
		"id":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e637281",
		"host":"http://127.0.0.1:5454/",
		"displayName":"Lara Croft",
                "url":"http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",

	},
        "status":"R"
}

Response status code and body format:

204 No Content
{
}

8. As an author, I want to know if I am friend with another author: /author/<AUTHOR1_ID>/friends/<AUTHOR2_ID> GET

<AUTHOR1_ID> is a uuid, <AUTHOR2_ID> is an url: servive/author/, this is required in the example-article.json.

Response status code and body format:

{	"query":"friends",
        # Array of Author UUIDs
        "authors":[
            "http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013",
            "http://127.0.0.1:5454/author/ae345d54-75b4-431b-adb2-fb6b9e547891"
        ],
        # boolean true or false
        "friends": true
}

Clone this wiki locally