Skip to content

Backend API Comment

DevinDai13 edited this page Apr 2, 2020 · 4 revisions

Comment

1. As an author, post a comment to a post: /posts/{POST_ID}/comments POST

Request format: Body required. Authorization required.

{
	"query": "addComment",
	"post":"http://127.0.0.1:8000/posts/bb1cb114-561e-4948-9891-bb33249bb380",
	"comment":{
	   	"author":{
                	"id":"http://127.0.0.1:5454/author/1d698d25-ff00-8f75-3845-3c120f581471",
                	"host":"http://127.0.0.1:5454/",
	        	"displayName":"Greg Johnson",
                	"url":"http://127.0.0.1:5454/author/1d698d25-ff00-8f75-3845-3c120f581471",
			"github": "http://github.com/gjohnson"
	        },
	   "comment":"this is comment 3 for post 1 by user 1",
	   "contentType":"text/markdown",
	   "published":"2015-03-09T13:07:04+00:00",
	   "id":"de305d54-75b4-431b-adb2-eb6b9e546013"
	}
}

Response status code and body format:

201 Created
{
    "query": "addComment",
    "success": "true",
    "message": "Comment Added"
}
401 Unauthorized
{
    "detail": "Invalid token."
}

2. As anyone, view all comments of a post: /posts/{POST_ID}/comments GET

Request format: Body not required. Authorization optional.

Response status code and body format:

200 OK
{
    "query": "comments",
    "count": 2,
    "size": 50,
    "next": null,
    "previous": null,
    "comments": [
        {
            "author": {
                "id": "https://spongebook.herokuapp.com/author/974dff1d-42eb-441e-9f1f-4d43acd5c0e2",
                "host": "https://spongebook.herokuapp.com/",
                "displayName": "user1",
                "url": "https://spongebook.herokuapp.com/author/974dff1d-42eb-441e-9f1f-4d43acd5c0e2"
            },
            "comment": "this is comment2 for post1 by user 1",
            "contentType": "text/markdown",
            "published": "2020-03-21T01:46:49-06:00",
            "id": "ab7cb0f6-5018-4479-a5cc-442f566f852e"
        },
        {
            "author": {
                "id": "https://spongebook.herokuapp.com/author/974dff1d-42eb-441e-9f1f-4d43acd5c0e2",
                "host": "https://spongebook.herokuapp.com/",
                "displayName": "user1",
                "url": "https://spongebook.herokuapp.com/author/974dff1d-42eb-441e-9f1f-4d43acd5c0e2"
            },
            "comment": "this is comment1 for post1 by user 1",
            "contentType": "text/markdown",
            "published": "2020-03-21T01:45:52-06:00",
            "id": "ab7cb0f6-5018-4479-a5cc-442f566f852c"
        }
    ]
}

Clone this wiki locally