Skip to content

Latest commit

 

History

History
95 lines (55 loc) · 3.71 KB

README.md

File metadata and controls

95 lines (55 loc) · 3.71 KB

Blogging API

This is a simple API for managing blogs and users. It allows users to create, publish, and manage their blogs. Users can also view published blogs, search for blogs, and edit their own blogs.

Features

  • User Authentication: Users can sign up, sign in, and authenticate using JWT (JSON Web Tokens) for secure access to the API endpoints.
  • Blog Management: Users can create new blogs, edit their own blogs, and publish them.
  • Blog Listing: Users and non-logged-in visitors can view lists of published blogs. The list is paginated and can be filtered, searched, and sorted by various criteria.
  • Blog Viewing: Users and visitors can view individual published blogs. The read_count of the blog is updated each time it is viewed.
  • User-specific Actions: Users can view a list of their own blogs, edit their own blogs, and view drafts.
  • Reading Time Calculation: The API estimates the reading time for each blog post based on average reading speed.

Prerequisites

  • Node.js installed on your system. You can download it from nodejs.org.
  • MongoDB database to store blog and user data.

Installation

  1. Clone the repository:

    git clone <repository-url>

  2. Install dependencies:

    cd blogging-api

    npm install

  3. Set up environment variables:

    Create a .env file in the project root and add the following variables:

    PORT=3000

    MONGODB_URI=<your-mongodb-uri>

    JWT_SECRET=<your-secret-key>

    Replace <your-mongodb-uri> with the connection URI for your MongoDB database and <your-secret-key> with a secret key for JWT authentication.

  4. Start the server:

    npm start

API Endpoints

User Authentication

  • POST /signup: Create a new user account.
  • POST /signin: Sign in and generate JWT token for authentication.

Blog Management

  • POST /blogs: Create a new blog (requires authentication).
  • PUT /blogs/:id: Edit an existing blog (requires authentication and ownership).
  • DELETE /blogs/:id: Delete a blog (requires authentication and ownership).

Blog Listing and Viewing

  • GET /blogs: Get a list of published blogs (paginated, searchable, filterable, and orderable).
  • GET /my-blogs: Get a list of user's own blogs (paginated, filterable by state).
  • GET /blogs/:id: Get a specific published blog with the author's information.

Additional Endpoints

  • GET /blogs/edit/:id: Get a specific blog for editing (requires authentication and ownership).

Usage

  1. User Authentication:
  • Use POST /signup to create a new user account by providing first_name, last_name, email, username, and password.
  • Use POST /signin to sign in with your email and password and obtain a JWT token for authentication.
  1. Blog Management:
  • Use POST /blogs to create a new blog. Provide title, description, tags, and body in the request body. The blog will be in draft state by default.
  • Use PUT /blogs/:id to edit an existing blog. Provide title, description, tags, and body in the request body. Only the owner can edit the blog.
  • Use DELETE /blogs/:id to delete a blog. Only the owner can delete the blog.
  1. Blog Listing and Viewing:
  • Use GET /blogs to get a list of published blogs. You can filter, search, sort, and paginate the results.
  • Use GET /my-blogs to get a list of your own blogs. You can filter by state and paginate the results.
  • Use GET /blogs/:id to view a specific published blog with the author's information.
  • Use GET /blogs/edit/:id to get a specific blog for editing. Only the owner can access this endpoint.

Contributors