This is a blog Api that can create, read, update and delete a post and comment.
The backend can be started with yarn run dev
after running the yarn
command to install the dependences, also make sure you have your mongoDB server
runing in the background for the database connection, and if you don't have nodemon
in your global machine, then you need to install it as a global or as a dependence.
Base URL:
/api/v1
-
-
Description:
Returns all posts in a json format. -
Parameters:
-
Required:
None -
Optional:
-
QueryStrings :
page : Integer
size : Integer
-
-
-
Request Body:
None -
Success Response:
-
Content:
{
statusCode : 200,
status :success
,
message :successful
,
data : {posts : [array of posts with comments]
,
allPostTotal : Integer
,
offset : Integer
,
pageSize : Integer
,
totalPages : Integer
,
currentPage : Integer
,
slNo : Integer
,
hasPrevPage : Boolean
,
hasNextPage : Boolean
}}
-
It returns empty array of post, if there are no post in the database
-
-
-
-
Description:
Creates a new post. -
Parameters:
-
Required:
None -
Optional:
None
-
-
Request Body:
-
Required:
postMessage : String
-
Optional:
postPictures : Array[]
-
-
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :successful
,
data : {postMessage : String
,
comments : [Array of comments]
,
totalComments : Integer
,
postPictures : [Array of pictures]
,
_id : String
,
createdAt : String
,
updatedAt : String
}}
-
Error Response:
-
Content:
{
statusCode : 500,
status :error
,
message :String
}
-
-
-
-
Description:
Returns a post that matches theid
in a json format. -
Parameters:
-
Required:
-
Path :
Id : String
-
-
Optional:
None
-
-
Request Body:
None -
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :Post
,
data : {totalComments : Integer
,
posts :
{
_id : String
,
postMessage : String
,
comments : [Array of comments]
,
totalComments : Integer
,
postPictures : [Array of pictures]
,
createdAt : String
,
updatedAt : String
}}
}
-
Error Response:
-
Content:
{
statusCode : 400,
status :error
,
message :String
}
-
-
-
-
Description:
Updates a post that matches theid
. -
Parameters:
-
Required:
-
Path :
Id : String
-
-
Optional:
None
-
-
Request Body:
-
Required:
postMessage : String
-
-
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :successful
,
data : {postMessage : String
,
comments : [Array of comments]
,
totalComments : Integer
,
postPictures : [Array of pictures]
,
_id : String
,
createdAt : String
,
updatedAt : String
}}
-
Error Response:
-
Content:
{
statusCode : 400,
status :error
,
message :String
}
-
-
-
-
Description:
Deletes a post that matches theid
. -
Parameters:
-
Required:
-
Path :
Id : String
-
-
Optional:
None
-
-
Request Body:
-
Required: None
-
Optional:
None
-
-
Success Response:
-
Content:
{
statusCode : 200,
status :success
,
message :String
}
-
-
Error Response:
-
Content:
{
statusCode : 400,
status :error
,
message :String
}
-
-
-
-
Description:
Creates a new comment under a post that marches thepostId
. -
Parameters:
-
Required:
-
Path :
postId : String
-
-
Optional:
None
-
-
Request Body:
-
Required:
commentMessage : String
-
-
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :successful
,
data : {commentMessage : String
,
_id : String
,
createdAt : String
,
updatedAt : String
}}
-
Error Response:
-
Content:
{
statusCode : 500,
status :error
,
message :String
}
-
-
-
-
Description:
Returns a comment that matches theid
in a json format. -
Parameters:
-
Required:
-
Path :
Id : String
-
-
Optional:
None
-
-
Request Body:
None -
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :successfully
,
data : {_id : String
,
commentMessage : String
,
createdAt : String
,
updatedAt : String
}}
-
Error Response:
-
Content:
{
statusCode : 400,
status :error
,
message :String
}
-
-
-
-
Description:
Updates a comment that matches theid
. -
Parameters:
-
Required:
-
Path :
Id : String
-
-
Optional:
None
-
-
Request Body:
-
Required:
commentMessage : String
-
-
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :successfully
,
data : {_id : String
,
commentMessage : String
,
createdAt : String
,
updatedAt : String
}}
-
Error Response:
-
Content:
{
statusCode : 500,
status :error
,
message :String
}
-
-
-
-
Description:
Returns all comments in a particular post that matches thepostId
in a json format. -
Parameters:
-
Required:
-
Path :
postId : String
-
-
Optional:
None
-
-
Request Body:
None -
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :successfully
,
data : [{
_id : String
,commentMessage : String
}]
}
-
Error Response:
-
Content:
{
statusCode : 400,
status :error
,
message :String
}
-
-
-
-
Description:
Deletes a comment that matches theid
under a post that matches thepostId
. -
Parameters:
-
Required:
-
Path :
Id : String
postId : String
-
-
Optional:
None
-
-
Request Body:
-
Required: None
-
Optional:
None
-
-
Success Response:
- Content:
{
statusCode : 200,
status :success
,
message :This comment is deleted successfully
,
data : [{
_id : String
,
commentMessage : String
,
updatedAt : String
}]
}
-
Error Response:
-
Content:
{
statusCode : 400,
status :error
,
message :String
}
-
-
hosted api link
:
https://blog-api-chubukas.vercel.app
- Node Js
- Express Js
- MongoDB
- cloudinary (for storing of post images)
If you are going to run this app on your local host You have to create a
config.env
file and save these variables:
- DATABASE (Link to your online monogoDb cluster )
- DATABASE_PASSWORD (The password to monogoDb cluster)
- DATABASE_LOCAL (Your local mongoDB Link)
- CLOUDINARY_NAME (Your cloudinary username)
- CLOUDINARY_API_KEY (Your cloudinary API key)
- CLOUDINARY_SECRET (Your cloudinary secret)