Skip to content

scriptWithKishan/Comprehensive-API-Development-and-Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comprehensive API Development and Management

This project is a secure and scalable RESTful API built with Node.js, Express and MongoDB. It includes CRUD operations, JWT based authentication and built with clean architecture principles with separate layers for routes, controllers, models and middlewares which ensures maintainability.

The user password is secured by hashing before saving to the database, token expiration is included for security, input validation to check for clean input and error handling with appropriate messages and status code for developers.

This project is fully tested on Postman by checking all the routes for errors and success messages. It also production ready which can be easily deployed to cloud platforms.

APIs

A RESTful API for managing user data with JWT-based authentication. This API provides endpoints for user registration, authentication, and CRUD operations on user records.

Base URL

http://localhost:4000

Authentication

This project uses JWT based authentication system which includes token in the authorization header for protected endpoints.

Authorization: Bearer <jwt-token>

Response Format

Success Response

{
    "status": "success",
    "message": "success message",
    date: {...}
}

Error Response

{
    "status": "error",
    "message": "error message"
}

Endpoints

  1. User Registration

    POST: /auth/users

    Request Body:

    {
        "name": "Kishan",
        "email": "kishan@mail.com",
        "password": "kishan123",
        "phone": "1234567"
    }
    

    Success Response:

    {
        "status":"success",
        "message":"User created successfully!"
    }
    

    Error Response:

    {
        "status":"error",
        "message":"User already exists!"
    }
    
  2. User Login

    POST /auth/login

    Request Body:

    {
        "email": "kishan@mail.com",
        "password": "kishan123"
    }
    

    Success Response:

    {
        "status": "success",
        "message": "User Logged in successfully!",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
    }
    

    Error Response:

    {
         "status":"error",
         "message":"Invalid credentials!"
    }
    
  3. Get All Users

    GET /users

     Authorization: Bearer <jwt-token>
    

    Success Response:

    {
        "status":"success",
        "data": [
            {
                "id":"6895aac93f14fcfbd822e70d",
                "name":"Kishan",
                "email":"kishan@mail.com",
                "phone":"1234567"
            },
            ...
            ]
    }
    
  4. Get User By ID

    GET /users/:id

     Authorization: Bearer <jwt-token>
    

    Success Response:

    {
        "status": "success",
        "data": {
            "id": "6894568fb24b2ef6aae32ed9",
            "name": "Kishan",
            "email": "kishan@mail.com",
            "phone": "1234567"
        }
    }
    

    Error Response:

    {
        "status":"error",
        "message":"User not found!"
    }
    
  5. Update User

    PUT /users/:id

     Authorization: Bearer <jwt-token>
    

    Request Body:

    {
        "name": "Krish",
        "email": "krish@mail.com",
        "password": "krish123",
        "phone": "999999"
    }
    

    Success Response:

    {
        "name": "Krish",
        "email": "krish@mail.com",
        "password": "krish123",
        "phone": "999999"
    }
    

    Error Response:

    {
        "status":"error",
        "message":"User not found!"
    }
    
  6. Delete User

    DELETE /users/:id

    Authorization: Bearer <jwt-token>
    

    Success Response:

    {
        "status": "success",
        "message": "User deleted successfully!"
    }
    

    Error Response:

    {
        "status":"error",
        "message":"User not found!"
    }
    

Setup Instructions

  1. Install Dependencies

    npm install
    
  2. Start MongoDB Server locally

  3. Run the application

    npm run dev
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published