Sabbirfeni / A64-API

This project provides a straightforward API for managing users and posts, utilizing modern technologies for backend and database functionality.

Home Page:https://abneribeiro.github.io/A64-API/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A64 POST API

This project is an application developed in Node.js using the MongoDB database. The application allows users to be created with a username, email, and password. Once created, they can create posts.

Technologies Used

  • Node.js
  • Express.js
  • MongoDB

Project Dependencies

  • Express-validator
  • Mongoose
  • JSON Web Tokens (JWT)
  • Bcrypt.js

Authentication

  • Middleware
  • Added authentication to ensure that only authenticated users can create posts and perform other actions.

How To Run The Project

  1. Clone the repository to your local machine using the command
  git clone https://github.com/abneribeiro/A64-API.git
  1. Navigate to the project directory using the command
  cd directory-name
  1. Install project dependencies using the command
  npm install
  1. Start the server using the command
  node app.js
  1. The application will be available at
  http://localhost:3000
  1. Use tools like Postman to test routes.

Project Directory Structure

project-backend/
├── controllers/
│   ├── authController.js
│   ├── postController.js
├── middleware/
│   ├── authMiddleware.js
├── models/
│   ├── User.js
│   ├── Post.js
├── routes/
│   ├── authRoutes.js
│   ├── postRoutes.js
├── app.js

API Endpoints and Actions

  1. Create Users
  • Endpoint: POST /user/register

  • Description: Creates a new user with a name and password. The user's ID is automatically generated by the backend.

  • Parameters:

    • username
    • email
    • password

    Response (JSON): Success (Status Code 201): Returns a success message along with information about the created post.

    Error (Status Code 401 or 500): Returns an error message in case of issues.

  1. Login Users
  • Endpoint: POST /user/login
  • Description: The user logs in by entering the name and password and generates a token.
  • Parameters:
    • username
    • password
  1. User Profile Update Authentication and Authorization
    • Profile update routes are protected using a JWT token. Include the token in the Authorization header of each request to protected routes.
  • Endpoint: PUT /users/profile

  • Description: The profile update functionality allows authenticated users to modify information such as their username, email and password. To access this feature, provide a valid JWT token obtained during login and must be included in the Authorization header of requests to protected routes. The server decodes the token to verify user authenticity. Provide the new data in the request body.

    • Parameters:

      • username : New name of the user (optional).
      • email : New email of the user (optional).
      • password : New password of the user (optional).
    • Response (JSON):

      • Success (Status Code 200): Returns a success message along with the updated user information.

      • Error (Status Code 401 or 500): Returns an error message in case of issues.

  1. Delete User
  • Endpoint: DELETE /users/profile

  • Description: Deletes a specific user based on the provided token.

  • Response (JSON):

    • Success (Status Code 200): Returns a success message along with the deleted user information.

    • Error (Status Code 401 or 500): Returns an error message in case of issues.

  1. Create Post
  • Endpoint: POST /posts/create
  • Description: Creates a new post for a specific user based on the provided user token.
  • Parameters:
    • title : Post title.
    • content : Post content.
  • Response (JSON):
    • _id
    • title
    • content
    • author
    • createdAt
  1. View All Posts
  • Endpoint: GET /posts/all

  • Description: Returns a list of posts from a specific user based on the provided user token.

  • Response (JSON - Array):

    • _id
    • title
    • content
    • author
    • createdAt
  1. View Posts by User ID
  • Endpoint: GET /posts/:userId
  • Description: Returns a list of posts from a specific user based on the provided user ID.
  • Parameters:
    • userId: ID of the user whose posts will be viewed.
  • Response (JSON - Array):
    • id : Post ID.
    • userId : ID of the user associated with the post.
    • content : Post content.
    • createdAt : Date and time of post creation.
  1. Delete Posts by User ID
  • Endpoint: DELETE /posts/:postId
  • Description: Deletes a specific post based on the provided post ID.
  • Parameters:
    • postId: ID of the post to be deleted.
  • Response (JSON):
    • message: User post deleted

Contribution and Bug Reporting

We appreciate your interest in contributing to our Open Source project! Your collaboration is crucial for the continuous improvement of our platform. If you're a dedicated programmer passionate about creating quality solutions, we're excited to welcome your contribution.

How to Contribute

  1. Fork the Repository: Begin by forking our GitHub repository. This will create a copy of the project in your own account.

  2. Clone the Repository: Clone your forked repository to your local development environment.

  3. Create a New Branch: Create a new branch for the work you intend to do. This helps keep development organized and enables discussion of proposed changes.

  4. Implement Enhancements or Fixes: Make the necessary code changes. Ensure you follow our style guidelines and best programming practices.

  5. Testing and Validation: Rigorously test your changes to ensure everything works as expected. Be sure to add new tests as well, when applicable.

  6. Submit a Pull Request: Submit a Pull Request (PR) from your branch to the main branch of the original repository. Clearly describe the purpose of the PR and include any relevant context.

Bug Reporting

If you've discovered a bug or issue on our platform, we'd like to hear about it so we can address it promptly. When reporting a bug, follow these steps:

  1. Search Before Reporting: Check if the bug has been reported previously in our issue tracking system. This helps to avoid duplications.

  2. Create a New Issue: If the bug hasn't been reported, create a new issue on our GitHub repository. Provide clear details about the issue, including steps to reproduce it.

  3. Include Context: If possible, provide additional information such as screenshots, error logs, and details about the environment in which the bug occurred.

What to Expect

We sincerely appreciate your contributions to our Open Source community. Our team will review your contributions and provide valuable feedback. Know that your time and effort are highly valued, and together, we can continue to enhance and strengthen our platform.

Thank you for joining us on this journey of development and continuous improvement!

Development Team

A64-Team

About

This project provides a straightforward API for managing users and posts, utilizing modern technologies for backend and database functionality.

https://abneribeiro.github.io/A64-API/


Languages

Language:JavaScript 100.0%