GithubHelp home page GithubHelp logo

blog_api's Introduction

Blog Backend API

Table of Contents

Introduction

This is a backend API for a blog application built with Node.js, Express, and MongoDB. The API supports user authentication, post creation, updating, deleting, liking, disliking, and commenting on posts.

Features

  • User Registration and Login with JWT-based authentication
  • Create, read, update, and delete posts
  • Like and dislike posts
  • Add, update, and delete comments on posts
  • Get user profile information along with the post count

Technologies Used

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • JWT (JSON Web Token)
  • bcrypt
  • dotenv
  • cookie-parser
  • cors

Getting Started

Prerequisites

  • Node.js and npm installed
  • MongoDB installed and running

Installation

  1. Clone the repository:
git clone https://github.com/shashankaz/blog_api.git
  1. Navigate to the project directory:
cd blog_api
  1. Install the dependencies:
npm install
  1. Create a .env file in the root directory and add the following environment variables:
PORT=3000
MONGO_URI=your_mongo_database_uri
JWT_SECRET=your_jwt_secret
  1. Start the server:
npm start

API Endpoints

Authentication

  • Register a new user

    POST /api/auth/register
    

    Request Body:

    {
      "name": "John Doe",
      "email": "[email protected]",
      "password": "password123",
      "bio": "Software Developer",
      "profilePicture": "url_to_profile_picture"
    }
  • Login a user

    POST /api/auth/login
    

    Request Body:

    {
      "email": "[email protected]",
      "password": "password123"
    }
  • Logout a user

    GET /api/auth/logout
    
  • Get user profile and post count

    GET /api/auth/profile
    

Post Management

  • Create a new post

    POST /api/posts
    

    Request Body:

    {
      "title": "My First Post",
      "content": "This is the content of my first post."
    }
  • Get all posts

    GET /api/posts
    
  • Get posts created by the logged-in user

    GET /api/posts/me
    
  • Get a single post by ID

    GET /api/posts/:id
    
  • Update a post

    PUT /api/posts/:id
    

    Request Body:

    {
      "title": "Updated Post Title",
      "content": "Updated content of the post."
    }
  • Delete a post

    DELETE /api/posts/:id
    
  • Like a post

    POST /api/posts/:id/like
    
  • Dislike a post

    POST /api/posts/:id/dislike
    

Comment Management

  • Add a comment to a post

    POST /api/posts/:id/comment
    

    Request Body:

    {
      "content": "This is a comment."
    }
  • Update a comment

    PUT /api/posts/:postId/comment/:commentId
    

    Request Body:

    {
      "content": "Updated comment content."
    }
  • Delete a comment

    DELETE /api/posts/:postId/comment/:commentId
    

blog_api's People

Contributors

shashankaz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.