Skip to content

Himanshu8862/BlogAPI

Repository files navigation

Blog API Application

Tech Stack

Server: NodeJs, ExpressJs, MongoDB, Mongoose, JWT

API FEATURES

  • Authentication & Authorization
  • Post CRUD operations
  • User can like/dislike posts
  • Comment functionality
  • User can create categories for posts
  • User can block/unblock different users
  • User who block another user cannot see his/her posts
  • Last date a post was created
  • Check if a user is active or not
  • Check last date a user was active
  • Changing user award based on number of posts created by the user
  • User can follow and unfollow another user
  • Get following and followers count
  • Get total profile viewers count
  • Get posts created count
  • Get blocked counts
  • Get all users who views someone's profile
  • Update user details and password
  • User can upload and update profile photo
  • Admin can block/unblock a user
  • User can close his/her account

ENDPOINTS

Run Locally

Clone the project

  git clone https://github.com/Himanshu8862/BlogAPI

Go to the project directory

  cd BlogAPI

Install dependencies

  npm install

Start the server

  npm run server

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

MONGODB_URL , JWT_TOKEN , CLOUDINARY_CLOUD_NAME , CLOUDINARY_API_KEY , CLOUDINARY_API_SECRET_KEY

baseURL = https://blog-api-6y9o.onrender.com/

API Authentication

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 to be sent in the Authorization header

Example:

Authorization: Bearer <YOUR_TOKEN>

Register a new API client

POST /api/v1/users/register
Parameter Type Description Required
authentication string Your token no
firstname string Your firstname yes
lastname string Your lastname yes
email string Your email yes
password string Your password yes

The request body needs to be in JSON format.

{
  "firstname": "John",
  "lastname": "Doe",
  "password": "myPassword",
  "email": "[email protected]"
}

User API Reference

User Login

POST /api/v1/users/login
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"
}

Get my profile

GET /api/v1/users/profile
Parameter Type Description Required
authentication string Your token yes

Get all users

GET /api/v1/users/
Parameter Type Description Required
authentication string Your token no

View a user profile

GET /api/v1/users/profile-viewers/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the user whose profile you want to view yes

Following a user

GET /api/v1/users/following/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the user you want to follow yes

Unfollowing a user

GET /api/v1/users/unfollowing/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the user you want to unfollow yes

Update user password

PUT /api/v1/users/update-password
Parameter Type Description Required
authentication string Your token yes
password string Enter new password yes

Example request body:

{
  "password": "value"
}

Update your profile

PUT /api/v1/users
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",
}

Block user

GET /api/v1/users/block/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the user you want to block yes

Unblock user

GET /api/v1/users/unblock/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the user you want to unblock yes

Admin blocking a user

PUT /api/v1/users/admin-block/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the user admin wants to block yes

Admin unblocking a user

PUT /api/v1/users/admin-unblock/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the user admin wants to unblock yes

Delete your account

DELETE /api/v1/users/delete-account
Parameter Type Description Required
authentication string Your token yes

Upload Profile Photo

PUT /api/v1/users/profile-photo-upload
Parameter Type Description Required
authentication string Your token yes
profile string Image to upload yes

Post API Reference

Create Post

POST /api/v1/posts
Parameter Type Description Required
authentication string Your token yes
title string Post title yes
description string Post description yes
category string ID of the category yes
photo string Image of the post yes

Example request body:

{
  "title": "value",
  "description": "value",
  "category": "value",
  "photo": "photo",
}

Get All Posts

GET /api/v1/posts
Parameter Type Description Required
authentication string Your token no

Get Single Post

GET /api/v1/posts/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the post yes

Toggle Post like

GET /api/v1/posts/likes/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the post yes

Toggle Post dislike

GET /api/v1/posts/dislikes/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the post yes

Update Post

PUT /api/v1/posts/:id
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 ID of the category yes
photo string Photo of the post yes

Example request body:

{
  "title": "value",
  "description": "value",
  "category": "value",
  "photo": "photo",
}

Delete Post

DELETE /api/v1/posts/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the post yes

Comment API Reference

Create Comment

POST /api/v1/comments/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the post yes
description string Description of the comment yes

Example request body:

{
  "description": "value"
}

Get Single Comment

GET /api/v1/comments/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the comment 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

PUT /api/v1/comments/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the comment yes

Example request body:

{
  "description": "value"
}

Category API Reference

Create Category

POST /api/v1/categories/
Parameter Type Description Required
authentication string Your token yes
title string title of the category yes

Example request body:

{
  "title": "value"
}

Get Single Category

GET /api/v1/categories/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the category yes

Get all categories

GET /api/v1/categories/
Parameter Type Description Required
authentication string Your token yes

Update Category

PUT /api/v1/categories/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the category yes
title string Title of the category yes

Example request body:

{
  "title": "value"
}

Delete Category

DELETE /api/v1/categories/:id
Parameter Type Description Required
authentication string Your token yes
id string ID of the category yes

Releases

No releases published

Packages

No packages published