Skip to content

ShivankSharma070/BlogManagmentBackend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blog Managment Backend

A REST API built with Express.js and Mongoose for connecting to MongoDB. This application provides user authentication and CRUD operation for a Blog Managment System.

Features

  • RESTful API endpoints
  • MongoDB integration with Mongoose
  • JWT authentication
  • Rate limitting Middleware

Prerequisites

Before you begin, ensure you have the following installed:

Installation

  1. Clone the repository

    git clone https://github.com/ShivankSharma070/BlogManagmentBackend.git
    cd BlogManagmentBackend/
  2. Install dependencies

    npm install
  3. Set up environment variables

    • Create a .env file in the root directory
    • Add your configuration (see Configuration)
  4. Start the server

    npm start

Configuration

Create a .env file with these variables:

PORT=3000
MONGODB_CONNECT_URL="<your-mongodb-connection-url>"
JWT_PRIVATE_KEY="<Your-private-key>"

Replace MONGODB_CONNECT_URL with your MongoDB connection string (use MongoDB Atlas URI for cloud databases) and JWT_PRIVATE_KEY with a private key you want to use for you JWT authentication.

Running the Application

  • Development mode :

    npm run dev
  • Production mode:

    npm start

The server will be available at http://localhost:3000 by default.

API Endpoints

Items Resource

Method Endpoint Description
POST /auth/login Login using email and password
POST /auth/register Register new user.
GET /auth/logout Logout current user.
GET /blog/s Get items by ID/Name
POST /blog/add Create a new blog
PUT /blog/update Update an existing blog by ID
DELETE /blog/delete Delete an blog by ID
POST /blog/comment Add comments to a blog by ID
GET /blog/like Like a blog by ID

Example Requests

Login (POST /auth/login)

/auth/login

Request Body should contain a json containing email and password

{
"email":"<user-email>",
"password":"<user-password>"
}

Logout (GET /auth/logout)

/auth/logout

Register (POST /auth/register)

/auth/register

Request body should have a json object like this

{
"name":"<user-name>",
"email":"<user-email>",
"password":"<user-password>"
}

Search Items (GET /blog/s)

/blog/s?query="yourQuery"
Parameter Description
id Blog unique id
query Query used to search Blog titles

Add Items (POST /blog/add)

/blog/add

Request body should contains a json like

{
    "title":"Blog title",
    "content":"Blog Content"
}

Update Items (POST /blog/update)

/blog/update?id="blog-id"
Parameter Description
id Unique id for blog

Request Body should contain a json with fields to update. For example

{
"title":"<new-title>" 
}

Delete Items (GET /blog/delete)

/blog/delete?id="blog-id"
Parameter Description
id Unique id for blog

Comment (POST /blog/comment)

/blog/comment?id="blog-id"
Parameter Description
id Unique id for blog

Request Body should contain a json with comments for a blog. For example

{
"comment":"Nice Blog" 
}

These comments can be a string or a array of strings

Like Blog (GET /blog/like)

/blog/like?id="blog-id"
Parameter Description
id Unique id for blog

Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Note: Replace all placeholder values (your-username, your-repo-name, etc.) with your actual project details. Update API endpoints and validation rules according to your specific application requirements.

About

This is a backend for a blog managment system.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published