-
Notifications
You must be signed in to change notification settings - Fork 3
Comments API Endpoint
GET: /api/author/{author_id}/posts/{post_id}/comments
Get a list of comments that belong to the logged-in user and the author of the post.
- NOTE:
- Authors can see all comments to their own posts.
- For a friend post, a logged-in friend can only see post owner's and their own comments if they made any
- Basic Auth or token in the header for authentication purpose
- Logged in user must be approved by admin
Request Header | Required / optional | Description | Type |
---|---|---|---|
Authorization | required | Authentication Token | String |
Sample header
--header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"
No body required
Pramas | Required / optional | Description | Type | More |
---|---|---|---|---|
page | optional | Page number | Param | Default: 1 |
size | optional | Number of items in a page | Param | Default: 20 |
The following is a sample response from the endpoint:
[
{
"type": "comment",
"id": "https://konnection-server.herokuapp.com//author/8e5a01f5-b9a2-436b-b29d-900a28d46068/posts/ede5c72c-afd9-4840-83d8-0de62e29e99f/comments/1c5f9de8-815b-421e-b938-a9aa40401660",
"author": {
"id": "58e438c5-6ba5-4aac-a044-e94dafc8d686",
"url": "",
"host": "http://127.0.0.1:8000",
"type": "author",
"github": "",
"username": "follower2",
"displayName": ""
},
"comment": "This is a comment",
"contentType": "text/markdown",
"published": "2021-03-23T04:39:26.333718Z"
}
]
Response Status Code
- 200 OK: List of comments for a post
- 401 Unauthorized: User not logged in
- 404 Not Found: Author, Post and/or Comment DNE
POST: /api/author/{author_id}/posts/{post_id}/comments/
Logged-in user can create a new comment for a post.
- Basic Auth or token in the header for authentication purpose
- Logged in user must be approved by admin
Request Header | Required / optional | Description | Type |
---|---|---|---|
Authorization | required | Authentication Token | String |
Sample header
--header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"
Payload | Required / optional | Description | Type | More |
---|---|---|---|---|
comment | Required | Comment | Text | |
contentType | optional | Content type for the comment | Chars (max 18) | Accepted Type: text/markdown, text/plain |
author | Required | Author making the comment | JSON | See below for example |
Sample Payload
{
"comment": "This is a comment",
"contentType": "text/markdown",
"author": {
"username": "follower2",
"type": "author",
"id": "58e438c5-6ba5-4aac-a044-e94dafc8d686",
"host": "http://127.0.0.1:8000",
"displayName": "",
"url": "",
"github": ""
}
}
The following is a sample response from the endpoint:
{
"type": "comment",
"id": "https://konnection-client.herokuapp.com/author/352b9cd6-32ae-4bf5-acd9-617a605d5059/posts/8ed765bb-26ee-4dab-822b-14b440d294ac/comments/68fc2be0-f2f9-4533-885c-30d7a29180e2",
"author": {
"id": "f57796cb5a0441fca3f1093620d327b2",
"url": "https://team6-project-socialdistrib.herokuapp.com/author/f57796cb5a0441fca3f1093620d327b2",
"host": "https://team6-project-socialdistrib.herokuapp.com/",
"type": "author",
"github": "www.google.ca",
"displayName": "RemoteC"
},
"comment": "I love this content!",
"contentType": "text/plain",
"published": "2021-04-07T02:27:55.418924Z"
}
Response Status Code
- 201 Created: Created comment
- 400 Bad Request: Missing required fields in the body
- 401 Unauthorized: User not logged in
- 403 Bad Request: Cannot comment on friend post because the user is not a friend
- 404 Not Found: Author, Post and/or Comment DNE
POST: /api/author/<post_owner_id>/posts/<post_id>/create_remote_comments/
Payload | Required / optional | Description | Type | More |
---|---|---|---|---|
type | optional | value: "comment" | Text | |
comment | Required | Comment | Text | |
comment_url | Required | Get this from the 'comment' field in the Post object | URL | |
contentType | Required | Content type for the comment | Chars (max 18) | Accepted Type: text/markdown, text/plain |
author | Required | Author making the comment | JSON | See below for example |
Sample Payload
{
"type": "comment",
"author": {
"username": "username",
"type": "author",
"id": "b530d119-83f7-47e5-8c33-2defa1507832", # will be automatically set to logged-in user's URL before sending
"host": "https://konnection-server.herokuapp.com/",
"displayName": "username",
"url": "https://konnection-server.herokuapp.com/author/b530d119-83f7-47e5-8c33-2defa1507832",
"github": ""
},
"comment": "This is a comment by username!",
"comment_url": "https://team6-project-socialdistrib.herokuapp.com/author/2bdec9ff7a234e439cae015a40a1ec60/posts/fa61cdf4a7a349ffa8f313e8bed42167/comments",
"contentType": "text/plain"
}
POST: /api/author/<post_owner_id>/posts/<post_id>/get_remote_comments/
Payload | Required / optional | Description | Type | More |
---|---|---|---|---|
comment_url | Required | Get this from the 'comment' field in the Post object | URL |
Sample Payload
{
"comment_url": "https://team6-project-socialdistrib.herokuapp.com/author/2bdec9ff7a234e439cae015a40a1ec60/posts/fa61cdf4a7a349ffa8f313e8bed42167/comments",
}
Response Status Code
- Depends on the remote server