-
Notifications
You must be signed in to change notification settings - Fork 2
Comments API
Jack Zhao edited this page Apr 7, 2019
·
10 revisions
Endpoint: /posts/{post_id}/comments
GET
: Get comments of a post.
POST
: Add a comment to a post.
Request
/posts/{post_id}/comments:
get:
summary: Get comments of a post
tags:
- comment
parameters:
- name: post_id
in: path
description: Post ID
schema:
type: string
required: true
- in: query
name: page
description: page number
schema:
type: integer
- in: query
name: size
description: size limit
schema:
type: integer
responses:
200:
$ref: "#/components/responses/GetCommentsResponse"
post:
summary: Add a comment to a post
tags:
- comment
parameters:
- name: post_id
in: path
description: Post ID
schema:
type: string
required: true
requestBody:
description: Comment properties
required: true
content:
application/json:
schema:
type: object
properties:
comment:
type: string
example: 'my comment'
contentType:
type: string
example: 'text/plain'
responses:
"200":
$ref: "#/components/responses/CreateCommentResponse"
"403":
$ref: "#/components/responses/CreateCommentResponse403"
Response
GetCommentsResponse:
description: Get comments response
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: "comments"
count:
type: integer
description: Number of comments
example: 1023
size:
type: integer
description: Comments size
example: 50
next:
type: string
description: Next page url
example: "http://service/posts/{post_id}/comments?page=5"
previous:
type: string
description: Previous page url
example: "http://service/posts/{post_id}/comments?page=3"
comments:
$ref: "#/components/schemas/ArrayOfComments"
CreateCommentResponse:
description: Create comment response
content:
application/json:
schema:
type: object
properties:
query:
type: string
success:
type: boolean
message:
type: string
example:
query: addComment
type: true
message: Comment added
CreateCommentResponse403:
description: Fail to create comment response
content:
application/json:
schema:
type: object
properties:
query:
type: string
success:
type: boolean
message:
type: string
example:
query: addComment
type: false
message: Comment not allowed
Example GET
GET
/posts/8602742a-dc26-4ad3-b4b4-e53e8c948c6b/comments (login required)
Account for testing
username: Dorrryu
password: !@#$%^&*
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"query": "getComments",
"count": 2,
"size": null,
"next": null,
"previous": null,
"comments": [
{
"id": "caf70621-5c19-4dd4-83b6-44948f16427a",
"post": "8602742a-dc26-4ad3-b4b4-e53e8c948c6b",
"author": {
"id": "7afa94d2-0e2f-41b4-947e-7fa46a91375b",
"email": "",
"bio": "None",
"host": "http://conet-socialdistribution.herokuapp.com",
"first_name": "",
"last_name": "",
"displayName": "Andoryu",
"url": "http://conet-socialdistribution.herokuapp.com/author/7afa94d2-0e2f-41b4-947e-7fa46a91375b",
"github": "https://github.com/AndoryuGuo"
},
"comment": "Nice pic",
"contentType": "text/plain",
"published": "2019-04-03T16:17:09.373722-06:00"
},
{
"id": "0a322d6d-6661-4912-aca9-d78ab7474d9e",
"post": "8602742a-dc26-4ad3-b4b4-e53e8c948c6b",
"author": {
"id": "fb7b1f21-1e65-4065-9228-eca6a60db396",
"email": "[email protected]",
"bio": "None",
"host": "http://conet-socialdistribution.herokuapp.com",
"first_name": "demo",
"last_name": "demo",
"displayName": "Demo",
"url": "http://conet-socialdistribution.herokuapp.com/author/fb7b1f21-1e65-4065-9228-eca6a60db396",
"github": ""
},
"comment": "so cute",
"contentType": "text/plain",
"published": "2019-04-03T18:03:30.974040-06:00"
}
]
}
Example POST
POST
/posts/93fc5481-2ba2-404b-ac2f-567f92dfc855/comments (login required)
Account for testing
username: Dorrryu
password: !@#$%^&*
REQUEST:
{
"query": "addComment",
"post": "http://conet-socialdistribution.herokuapp.com/posts/93fc5481-2ba2-404b-ac2f-567f92dfc855",
"comment": {
"author": {
"id": "732a94d2-0e2f-41b4-947e-7fa46a91375b",
"host": "http://conet-socialdistribution.herokuapp.com",
"displayName": "Andoryu",
"url": "http://conet-socialdistribution.herokuapp.com/author/7afa94d2-0e2f-41b4-947e-7fa46a91375b"
},
"comment": "post from api",
"contentType": "text/plain",
"published": "2019-04-07T01:55:47.432Z",
"id": "d33fec32-4a2f-49de-8c91-9c62f13e94b7"
}
}
RESPONSE:
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"query": "addComment",
"type": true,
"message": "Successfully added comment."
}