Skip to content

Backend API Post

HumphreyLu6 edited this page Mar 22, 2020 · 13 revisions

Post

0. As anyone, view an author's timeline posts: /author/{AUTHOR_ID}/posts GET

/author/{AUTHOR_ID}/posts?page=1&size=5 GET

Request format: Body not required. Authorization optional.

Response status code and body format:

200 OK
{
    "query": "posts",
    "count": 3,
    "size": 50,
    "next": null,
    "previous": null,
    "posts": [
        {
            "title": "post3",
            "source": "https://spongebook.herokuapp.com/posts/ceb360b5-4d35-4069-8af6-330090884b0c",
            "origin": "https://spongebook.herokuapp.com/posts/ceb360b5-4d35-4069-8af6-330090884b0c",
            "description": "",
            "contentType": "text/markdown",
            "content": "this is post3 by user2",
            "author": {
                "id": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa",
                "host": "https://spongebook.herokuapp.com/",
                "displayName": "user2",
                "url": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa"
            },
            "categories": [],
            "comments": [],
            "published": "2020-03-21T01:44:59.123661-06:00",
            "id": "ceb360b5-4d35-4069-8af6-330090884b0c",
            "visibility": "PUBLIC",
            "visibleTo": [],
            "unlisted": false
        },
        {
            "title": "post2",
            "source": "https://spongebook.herokuapp.com/posts/a545a5ab-2f84-4a58-9c58-ade985aa0191",
            "origin": "https://spongebook.herokuapp.com/posts/a545a5ab-2f84-4a58-9c58-ade985aa0191",
            "description": "",
            "contentType": "text/markdown",
            "content": "this is post2 by user2",
            "author": {
                "id": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa",
                "host": "https://spongebook.herokuapp.com/",
                "displayName": "user2",
                "url": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa"
            },
            "categories": [],
            "comments": [],
            "published": "2020-03-21T01:44:40.281350-06:00",
            "id": "a545a5ab-2f84-4a58-9c58-ade985aa0191",
            "visibility": "PUBLIC",
            "visibleTo": [],
            "unlisted": false
        },
        {
            "title": "post1",
            "source": "https://spongebook.herokuapp.com/posts/bb1cb114-561e-4948-9891-bb33249bb380",
            "origin": "https://spongebook.herokuapp.com/posts/bb1cb114-561e-4948-9891-bb33249bb380",
            "description": "",
            "contentType": "text/markdown",
            "content": "this is post 1 by user 2",
            "author": {
                "id": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa",
                "host": "https://spongebook.herokuapp.com/",
                "displayName": "user2",
                "url": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa"
            },
            "categories": [],
            "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 comment1 for post1 by user 1",
                    "contentType": "text/markdown",
                    "published": "2020-03-21T01:45:52-06:00",
                    "id": "ab7cb0f6-5018-4479-a5cc-442f566f852c"
                },
                {
                    "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"
                }
            ],
            "published": "2020-03-21T01:44:25.145297-06:00",
            "id": "bb1cb114-561e-4948-9891-bb33249bb380",
            "visibility": "PUBLIC",
            "visibleTo": [],
            "unlisted": false
        }
    ]
}

1. As anyone, view all posts that are visible to me: /author/posts GET

Request format: Body not required. Authorization optional.

Response status code and body format:

200 OK
Same as 0.'s responses.

2. As anyone, view all posts marked as public on the local server: /posts GET

Request format: Body not required.

Response status code and body format:

200 OK
Same as 0.'s responses.

3. As anyone, view a single post: /posts/{POST_ID} GET

Request format: Body not required. Authorization optional.

Response status code and body format:

200 OK
{
    "title": "post1",
    "source": "https://spongebook.herokuapp.com/posts/bb1cb114-561e-4948-9891-bb33249bb380",
    "origin": "https://spongebook.herokuapp.com/posts/bb1cb114-561e-4948-9891-bb33249bb380",
    "description": "",
    "contentType": "text/markdown",
    "content": "this is post 1 by user 2",
    "author": {
        "id": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa",
        "host": "https://spongebook.herokuapp.com/",
        "displayName": "user2",
        "url": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa"
    },
    "categories": [],
    "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 comment1 for post1 by user 1",
            "contentType": "text/markdown",
            "published": "2020-03-21T01:45:52-06:00",
            "id": "ab7cb0f6-5018-4479-a5cc-442f566f852c"
        },
        {
            "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"
        }
    ],
    "published": "2020-03-21T01:44:25.145297-06:00",
    "id": "bb1cb114-561e-4948-9891-bb33249bb380",
    "visibility": "PUBLIC",
    "visibleTo": [],
    "unlisted": false
}
404 Not Found
{
    "detail": "Not found."
}

4. As an author, post a post: /posts POST

Request format: Authorization required.

{
    "title": "post5",
    "description": "des 5",
    "contentType": "text/plain",
    "content": "this is post5 by user1",
    "categories": ["study"],
    "visibility": "PRIVATE",
    "visibleTo": ["https://spongebook.herokuapp.com/author/49db2666-1cb5-4f96-bd29-c275db38d1e1"],
    "unlisted": true
}

Response status code and body format:

201 Created
{
    "title": "post5",
    "source": "https://spongebook.herokuapp.com/posts/95417cb7-9852-4531-b5b7-8723c5f82a07",
    "origin": "https://spongebook.herokuapp.com/posts/95417cb7-9852-4531-b5b7-8723c5f82a07",
    "description": "des 5",
    "contentType": "text/plain",
    "content": "this is post5 by user1",
    "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"
    },
    "categories": [
        "study"
    ],
    "comments": [],
    "published": "2020-03-21T02:34:03.049429-06:00",
    "id": "95417cb7-9852-4531-b5b7-8723c5f82a07",
    "visibility": "PRIVATE",
    "visibleTo": [
        "https://spongebook.herokuapp.com/author/49db2666-1cb5-4f96-bd29-c275db38d1e1"
    ],
    "unlisted": true
}
400 Bad Request
{
    "title": [
        "This field is required."
    ]
}

5. As an author, update a post: /posts/{POST_ID} PATCH

Request format: Authorization required.

{
    "description": "des6"
}

Response status code and body format:

200 OK
{
    "title": "post5",
    "source": "https://spongebook.herokuapp.com/posts/95417cb7-9852-4531-b5b7-8723c5f82a07",
    "origin": "https://spongebook.herokuapp.com/posts/95417cb7-9852-4531-b5b7-8723c5f82a07",
    "description": "des6",
    "contentType": "text/plain",
    "content": "this is post5 by user1",
    "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"
    },
    "categories": [
        "study"
    ],
    "comments": [],
    "published": "2020-03-21T02:34:03.049429-06:00",
    "id": "95417cb7-9852-4531-b5b7-8723c5f82a07",
    "visibility": "PRIVATE",
    "visibleTo": [
        "https://spongebook.herokuapp.com/posts/49db2666-1cb5-4f96-bd29-c275db38d1e1"
    ],
    "unlisted": true
}

Response status code and body format:

6. As an author, delete a post: /posts/{POST_ID} DELETE

Request format: Body not required. Authorization required.

Response status code and body format:

204 No Content