A Simple Blog server.
- MongoDB
npm install
node server.js
Request URL: /api/posts
Method: POST
Body:
{
"title": "First blog",
"text": "My First Blog\n\nIt is awesome.\n\nI like it."
}
{
"_id": "599d212fa69dd4742dda0cc7",
"text": [
{
"_id": "599d212fa69dd4742dda0cca",
"content": "My First Blog"
},
{
"_id": "599d212fa69dd4742dda0cc9",
"content": "It is awesome."
},
{
"_id": "599d212fa69dd4742dda0cc8",
"content": "I like it."
}
],
"title": "First blog",
"created": "2017-08-23T06:31:11.868Z"
}
Explanation: I have divided blog text into a dict where paragraph has ID. So I can load the comments on that paragraph.
Request URL: /api/post/:postid
Example: /api/post/599d212fa69dd4742dda0cc7
Method: GET
[
{
"_id": "599d212fa69dd4742dda0cc7",
"text": [
{
"_id": "599d212fa69dd4742dda0cca",
"content": "My First Blog"
},
{
"_id": "599d212fa69dd4742dda0cc9",
"content": "It is awesome."
},
{
"_id": "599d212fa69dd4742dda0cc8",
"content": "I like it."
}
],
"title": "First blog",
"created": "2017-08-23T06:31:11.868Z"
}
]
Request URL: /api/posts
Method: GET
[
{
"_id": "599d212fa69dd4742dda0cc7",
"text": [
{
"_id": "599d212fa69dd4742dda0cca",
"content": "My First Blog"
},
{
"_id": "599d212fa69dd4742dda0cc9",
"content": "It is awesome."
},
{
"_id": "599d212fa69dd4742dda0cc8",
"content": "I like it."
}
],
"title": "First blog",
"created": "2017-08-23T06:31:11.868Z"
}
...
...
4 More Posts
...
...
]
Explanation: As requirement, API is returning only first 5 posts.
Request URL: /api/posts/:pageNumber
Example: /api/posts/2
Method: GET
Explanation: As requirement, API is returning only first 5 posts. Pass page number to get post according to page. Eg. for page 2, give 2.
Request URL: /api/comment
Method: POST
Body: {
"paragraphId": "599d212fa69dd4742dda0cca",
"content": "I am a comment."
}
{
"paragraphId": "599d212fa69dd4742dda0cca",
"_id": "599d2574a69dd4742dda0ccc",
"content": "I am a comment.",
"created": "2017-08-23T06:49:24.665Z"
}
Request URL: /api/comment/:paragraphId
Example: /api/comment/599d212fa69dd4742dda0cca
Method: GET
[
{
"_id": "599d2574a69dd4742dda0ccc",
"paragraphId": "599d212fa69dd4742dda0cca",
"content": "I am a comment.",
"created": "2017-08-23T06:49:24.665Z"
}
]