API Specification
Contributors: Alicia Wang, Conner Swenberg
Values wrapped in < >
are placeholders for what the field values should be. Also be sure to read the request route carefully when you implement it - typos WILL cause test cases to fail!
NOTE ABOUT ERROR RESPONSES
The server should return an error response for:
POST
requests, if the user does not supply one of the fields in the body (e.g. title, link, username, text, etc.) with a status code of 400 (bad request)Any request if the id in the URL does not exist, with a status code of 404 (not found)
{
"error": "Your error message here"
}
For each of the following routes, we will specify a success response that you must implement, but make sure to also implement error responses accordingly!
Expected Functionality
Get all posts
GET
/api/posts/
<HTTP STATUS CODE 200>
{
"posts": [
{
"id": 0,
"upvotes": 1,
"title": "My cat is the cutest!",
"link": "https://i.imgur.com/jseZqNK.jpg",
"username": "alicia98"
},
{
"id": 1,
"upvotes": 3,
"title": "Cat loaf",
"link": "https://i.imgur.com/TJ46wX4.jpg",
"username": "alicia98"
},
...
]
}
Create a post
POST
/api/posts/
{
"title": "I love my dog!",
"link": "https://i.imgur.com/XsaLqi1.jpg",
"username": "raahi014"
}
<HTTP STATUS CODE 201>
{
"id": <Incremented ID>,
"upvotes": 1,
"title": "I love my dog!",
"link": "https://i.imgur.com/XsaLqi1.jpg",
"username": "raahi014"
}
Get a specific post
GET
/api/posts/{id}/
<HTTP STATUS CODE 200>
{
"id": <ID>,
"upvotes": <STORED UPVOTES OF POST WITH ID {id}>,
"title": <STORED TITLE OF POST WITH ID {id}>,
"link": <STORED LINK OF POST WITH ID {id}>,
"username": <STORED USERNAME OF POST WITH ID {id}>
}
Delete a specific post
DELETE
/api/posts/{id}/
<HTTP STATUS CODE 200>
{
"id": <ID>,
"upvotes": <STORED UPVOTES OF DELETED POST WITH ID {id}>,
"title": <STORED TITLE OF DELETED POST WITH ID {id}>,
"link": <STORED LINK OF DELETED POST WITH ID {id}>,
"username": <STORED USERNAME OF DELETED POST WITH ID {id}>
}
Get comments for a specific post
GET
/api/posts/{id}/comments/
<HTTP STATUS CODE 200>
{
"comments": [
{
"id": 0,
"upvotes": 8,
"text": "Wow, my first Reddit gold!",
"username": "alicia98"
},
...
]
}
Post a comment for a specific post
POST
/api/posts/{id}/comments/
Note: comments should have globally unique IDs! That is, if a comment on one post has ID 5, no other comments, even on other posts should have an ID of 5!
{
"text": "what a cute puppy aww",
"username": "raahi014"
}
<HTTP STATUS CODE 201>
{
"id": <COMMENT ID>,
"upvotes": 1,
"text": "what a cute puppy aww",
"username": "raahi014"
}
Edit a comment for a specific post
POST
/api/posts/{pid}/comments/{cid}/
{
"text": "what a cute puppy aww (edit): omg ty for the likes"
}
<HTTP STATUS CODE 200>
{
"id": <CID>,
"upvotes": <# UPVOTES>,
"text": "what a cute puppy aww (edit): omg ty for the likes",
"username": <USERNAME>
}
Last updated
Was this helpful?