Skip to content

sagites/bloggingApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blogging API

Welcome to the Blogging API project! This API was created as a challenge inspired by roadmap.sh, aimed at honing skills in MongoDB, Node.js, asynchronous programming, and problem-solving.

Features

  • Create, read, update, and delete blog posts
  • User authentication and authorization
  • Comment on posts
  • Like and dislike posts
  • Filter posts by categories and tags
  • Search functionality

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/blogging-api.git
    cd blogging-api
  2. Install the dependencies:

    npm install
  3. Create a .env file in the root directory and add your MongoDB URI and other environment variables:

    MONGO_URI=your_mongodb_uri
    JWT_SECRET=your_jwt_secret

Usage

  1. Start the server:

    npm start
  2. Using Postman to test the API:

    • Open Postman.
    • Load the API endpoints to interact with the Blogging API.

Endpoints

Authentication

  • Register a new user

    POST /api/auth/register
    • Body:
      {
          "username": "string",
          "email": "string",
          "password": "string"
      }
  • Login

    POST /api/auth/login
    • Body:
      {
          "email": "string",
          "password": "string"
      }

Posts

  • Create a new post

    POST /api/posts
    • Headers:
      {
          "Authorization": "Bearer <token>"
      }
    • Body:
      {
          "title": "string",
          "content": "string",
          "tags": ["string"],
          "category": "string"
      }
  • Get all posts

    GET /api/posts
  • Get a single post

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

    PUT /api/posts/:id
    • Headers:
      {
          "Authorization": "Bearer <token>"
      }
    • Body:
      {
          "title": "string",
          "content": "string",
          "tags": ["string"],
          "category": "string"
      }
  • Delete a post

    DELETE /api/posts/:id
    • Headers:
      {
          "Authorization": "Bearer <token>"
      }

Comments

  • Add a comment to a post

    POST /api/posts/:id/comments
    • Headers:
      {
          "Authorization": "Bearer <token>"
      }
    • Body:
      {
          "content": "string"
      }
  • Get comments for a post

    GET /api/posts/:id/comments
  • Delete a comment

    DELETE /api/posts/:postId/comments/:commentId
    • Headers:
      {
          "Authorization": "Bearer <token>"
      }

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published