Skip to content

Create a new Comment on a Post

Fraser Redford edited this page Apr 15, 2021 · 1 revision

POST author/<str:author_id>/posts/<str:post_id>/comments

Creates a post with the data specified in the body and a generated id.

Request Header

Basic authorization (base64 encoded username:password):
--header "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="

or token authorization is required:
--header "Authorization: Token 9d9ed917fe1ead2d1e27ac7dc233348ed2e3d4c0"

Request body

Field Name: Value:
type (Optional) "comment"
author (Required) Should contain a valid author object, see Author API
comment (Required) Should contain the the text of the comment itself
comments (Optional) Can optionally contain the link to the comments of the object that is being commented on
contentType (Required) Should contain the content type of the "comment" field

Sample Response

{
    "type": "comment",
    "author": {
        "type": "author",
        "id": "https://team6-project-socialdistrib.herokuapp.com/author/21d2d52bf3c34b84a45951d53b472a08",
        "host": "https://team6-project-socialdistrib.herokuapp.com/",
        "displayName": "Jeff",
        "url": "http://team6-project-socialdistrib.herokuapp.com/author/21d2d52bf3c34b84a45951d53b472a08",
        "github": "https://github.com/jeff/"
    },
    "comment": "I love this content!",
    "contentType": "text/plain",
    "published": "2021-03-28T05:23:03.889606Z",
    "id": "https://team6-project-socialdistrib.herokuapp.com/author/42d2d52bf6c44b84a44951d53b572a08/posts/aa5d8caa15954e42a39698588f0c473e/comments/ac40f36781874a50a6903e49dcd0fee6"
}

Response Codes

  • 201 CREATED for a successful comment
  • 404 NOT FOUND if the post to comment on is not found in database
  • 403 FORBIDDEN if the request is not the authenticated or the authenticated user is not the comments author
  • 400 BAD REQUEST if the request to create the comment on a remote server is not accepted

Clone this wiki locally