Blog API Application Project
bcrypt
cloudinary
cors
dotenv
express
express-async-errors
express-mongo-sanitize
express-rate-limit
helmet
hpp
http-status-codes
jsonwebtoken
mongoose
multer
multer-storage-cloudinary
nodemon
validator
xss-clean
cookie-parser
Authentication & Authorization
Post CRUD operations
User CRUD operations
Comment CRUD operations
Category CRUD operations
like and dislike a comment
Admin can suspend and unsuspend a user
A user can block different users
A user who block another user cannot see his/her posts
blocked user cannot see the profile of the user who blocked him/her
blocked user cannot follow the user who blocked him/her
blocked user cannot like, dislike or comment the post of the user who blocked him/her
A user can like and dislike a post
total likes and dislikes count
Changing user award base on number of posts created by the user
A user can follow and unfollow another user
Get following and followers count
Get posts of following users
A user can view another user's profile
Get total profile viewers count
Get posts created count
Get blocked counts
Get all users who views someone's profile
Update password
Profile photo uploaded
Upload images with posts
A user can delete his/her account
Using refresh token to get a new access token
Access token stored in a cookie
Clone the project
git clone https://link-to-project
Go to the project directory
Install dependencies
Start the server
To run this project, you will need to add the following environment variables to your .env file
MONGODB_URL
JWT_SECRET
JWT_EXPIRE
JWT_COOKIE_EXPIRES_IN
Some endpoints may require authentication for example. To create a create/delete/update post, you need to register your API client and obtain an access token.
The endpoints that require authentication expect a bearer token sent in the Authorization header
.
Example :
Authorization: Bearer YOUR TOKEN
Register a new API client
POST /api/v1/users/register
The request body needs to be in JSON format.
Parameter
Type
Description
Required
authentication
string
Your token
no
email
string
Your email
yes
password
string
Your password
yes
Example request body:
{
"email" :"your email"
"password" :"your password"
}
POST /api/v1/users/refresh-token
Body
Type
Description
Required
JWT refresh token
string
Your token
yes
Example request body:
{
"refreshToken" :"your refresh token"
}
GET /api/v1/users/profile
Parameter
Type
Description
Required
authentication
string
Your token
yes
Parameter
Type
Description
Required
authentication
string
Your token
no
GET /api/v1/users/view-profile/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the user you want to view his profile
yes
POST /api/v1/users/follow-user/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the user you want to follow
yes
POST /api/v1/users/unfollow-user/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the user you want to follow
yes
PATCH /api/v1/users/update-password
Parameter
Type
Description
Required
authentication
string
Your token
yes
password
string
Enter your password
yes
Example request body:
PATCH /api/v1/users/update-me
Parameter
Type
Description
Required
authentication
string
Your token
yes
email
string
Enter your email
no
firstname
string
Enter your firstname
no
lastname
string
Enter your lastname
no
Example request body:
{
"email" :"value" ,
"firstname" :"value" ,
"lastname" :"value" ,
}
PATCH /api/v1/users/block-user/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
Id of the user you want to block
yes
PATCH /api/v1/users/unblock-user/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
Id of the user you want to unblock
yes
PATCH /api/v1/users/suspend-user/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
Id of the user you want to block
yes
PATCH /api/v1/users/unsuspend-user/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
Id of the user you want to unblock
yes
DELETE /api/v1/users/delete-me
Parameter
Type
Description
Required
authentication
string
Your token
yes
POST /api/v1/users/profile-photo-upload
Parameter
Type
Description
Required
authentication
string
Your token
yes
profilePhoto
string
Image to upload
yes
Parameter
Type
Description
Required
authentication
string
Your token
yes
title
string
Post title
yes
description
string
Post description
yes
category
string
Name of the category
no
photo
string
Image of the post
no
Example request body:
{
"title" :"value" ,
"description" :"value" ,
"category" :"value" ,
"photo" :"photo" ,
}
Parameter
Type
Description
Required
authentication
string
Your token
no
GET /api/v1/posts/posts-of-following-user
Parameter
Type
Description
Required
authentication
string
Your token
yes
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the post
yes
GET /api/v1/like-post/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the post
yes
GET /api/v1/posts/dislike-post/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the post
yes
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the post
yes
title
string
title of the post
yes
description
string
description of the post
yes
category
string
category of the post
no
photo
string
photo of the post
no
Example request body:
{
"title" :"value" ,
"description" :"value" ,
"category" :"value" ,
"photo" :"photo" ,
}
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the post
yes
Comment API Reference
Create Comment
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the post
yes
Delete Comment
DELETE /api/v1/comments/:id
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the comment
yes
Update Comment
Parameter
Type
Description
Required
authentication
string
Your token
yes
id
string
ID of the post
yes