Skip to content

🏫 This is a basic CRUD application for managing users and products, to be consumed in a Frontend application."

License

Notifications You must be signed in to change notification settings

dev-madepozo/express-crud-users

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Express crud users & products

This is a basic CRUD application for managing users and products, designed as part of a Frontend course.

About

This is a simple CRUD API built using Express.js and MongoDB for managing users and products data. The API provides endpoints to create, retrieve, update, and delete users in a MongoDB database, making it a perfect starting point for understanding RESTful APIs, Node.js, and MongoDB integration.

Table of Contents

  1. Getting Started
  2. Features
  3. API Endpoints
  4. Collaboration
  5. License

Getting Started

To get started with this project locally, follow these steps:

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/dev-madepozo/cibertec-crud-users.git
  2. Navigate into the project directory:

    cd cibertec-crud-users
  3. Install the dependencies:

    npm install
  4. Create a .env file in the root directory and add your MongoDB connection string:

    MONGODB_URI=your_mongodb_connection_string
    PORT=8080
    
  5. Start the development server:

    npm dev
  6. The API will now be running on http://localhost:8080.

Example

To test the API, you can use tools like Postman or cURL.

Features

  • Create User: Add new users to the database.

  • Read User: Retrieve user information based on user ID.

  • Update User: Update user information (e.g., name, email, etc.).

  • Delete User: Delete a user from the database.

  • MongoDB integration: Data is stored and managed in a MongoDB database.

  • Create Product: Add new products to the database.

  • Read Product: Retrieve product information based on product ID.

  • Update Product: Update product information (e.g., name, description, price, etc.).

  • Delete Product: Delete a product from the database.

API Endpoints

The following API endpoints are available for users:

1. POST /api/v1/users

  • Description: Create a new user.
  • Request Body:
    {
        "firstName": "John",
        "lastName": "Doe",
        "username": "johndoe",
        "email": "john.doe@example.com",
        "phone": "9999999999",
        "website": "https://johndoe.com"
    }
  • Response:
    {
        "message": "User created successfully",
        "user": {
            "firstName": "John",
            "lastName": "Doe",
            "username": "johndoe",
            "email": "john.doe@example.com",
            "phone": "9999999999",
            "website": "https://johndoe.com",
            "id": "60c72bdf5f1b2c001f1f5c9f",
            "createdAt": 2024-12-03T16:03:23.224+00:00,
            "updatedAt": 2024-12-03T16:03:23.224+00:00
        }
    }

2. GET /api/v1/users

  • Description: Get a list of all users.
  • Response:
    [
        {
            "firstName": "John",
            "lastName": "Doe",
            "username": "johndoe",
            "email": "john.doe@example.com",
            "phone": "9999999999",
            "website": "https://johndoe.com",
            "id": "60c72bdf5f1b2c001f1f5c9f",
            "createdAt": 2024-12-03T16:03:23.224+00:00,
            "updatedAt": 2024-12-03T16:03:23.224+00:00
        }
    ]

3. GET /api/v1/users/:userId

  • Description: Get a specific user by ID.
  • Response:
    {
        "firstName": "John",
        "lastName": "Doe",
        "username": "johndoe",
        "email": "john.doe@example.com",
        "phone": "9999999999",
        "website": "https://johndoe.com",
        "id": "60c72bdf5f1b2c001f1f5c9f",
        "createdAt": 2024-12-03T16:03:23.224+00:00,
        "updatedAt": 2024-12-03T16:03:23.224+00:00
    }

4. PUT /api/v1/users/:userId

  • Description: Update the user's information.

  • Request Body:

    {
        "firstName": "Johnathan",
        "email": "johnathan.doe@example.com",
    }
  • Response:

    {
        "message": "User updated successfully",
        "user": {
            "firstName": "Johnathan",
            "lastName": "Doe",
            "username": "johndoe",
            "email": "johnathan.doe@example.com",
            "phone": "9999999999",
            "website": "https://johndoe.com",
            "id": "60c72bdf5f1b2c001f1f5c9f",
            "createdAt": 2024-12-03T16:03:23.224+00:00,
            "updatedAt": 2024-12-03T18:25:29.224+00:00
        }
    }

5. DELETE /api/v1/users/:userId

  • Description: Delete a user by ID.
  • Response:
    {
        "message": "User deleted successfully"
    }

The following API endpoints are available for products:

1. POST /api/v1/products

  • Description: Create a new product.
  • Request Body:
    {
        "name": "New TV",
        "description": "Doe",
        "price": 1999.99,
        "stock": 10,
        "category": "TV",
    }
  • Response:
    {
        "message": "Product was created successfully",
        "user": {
            "name": "New TV",
            "description": "Doe",
            "price": 1999.99,
            "stock": 10,
            "category": "TV",
            "id": "60c72bdf5f1b2c001f1f5c9f",
            "createdAt": 2024-12-03T16:03:23.224+00:00,
            "updatedAt": 2024-12-03T16:03:23.224+00:00
        }
    }

2. GET /api/v1/products

  • Description: Get a list of all products.
  • Response:
    [
        {
            "name": "New TV",
            "description": "Doe",
            "price": 1999.99,
            "stock": 10,
            "category": "TV",
            "id": "60c72bdf5f1b2c001f1f5c9f",
            "createdAt": 2024-12-03T16:03:23.224+00:00,
            "updatedAt": 2024-12-03T16:03:23.224+00:00
        }
    ]

3. GET /api/v1/products/category/:categoryName

  • Description: Get a list of all products by category.
  • Response:
    [
        {
            "name": "New TV",
            "description": "Doe",
            "price": 1999.99,
            "stock": 10,
            "category": "TV",
            "id": "60c72bdf5f1b2c001f1f5c9f",
            "createdAt": 2024-12-03T16:03:23.224+00:00,
            "updatedAt": 2024-12-03T16:03:23.224+00:00
        }
    ]

4. GET /api/v1/products/:productId

  • Description: Get a specific product by ID.
  • Response:
    {
        "name": "New TV",
        "description": "Doe",
        "price": 1999.99,
        "stock": 10,
        "category": "TV",
        "id": "60c72bdf5f1b2c001f1f5c9f",
        "createdAt": 2024-12-03T16:03:23.224+00:00,
        "updatedAt": 2024-12-03T16:03:23.224+00:00
    }

5. PUT /api/v1/users/:userId

  • Description: Update the product's information.

  • Request Body:

    {
        "name": "Sansumg UHD TV 65\"",
    }
  • Response:

    {
        "message": "Product updated successfully",
        "user": {
            "name": "Sansumg UHD TV 65\"",
            "description": "Doe",
            "price": 1999.99,
            "stock": 10,
            "category": "TV",
            "id": "60c72bdf5f1b2c001f1f5c9f",
            "createdAt": 2024-12-03T16:03:23.224+00:00,
            "updatedAt": 2024-12-03T18:25:29.224+00:00
        }
    }

6. DELETE /api/v1/product/:productId

  • Description: Delete a product by ID.
  • Response:
    {
        "message": "Product deleted successfully"
    }

Collaboration

Feel free to fork this project and submit pull requests. Contributions are welcome to help improve this API.

Steps to contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Make your changes and commit them (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Thank you for using this project! If you have any questions or need further assistance, feel free to open an issue or contact the repository owner.

About

🏫 This is a basic CRUD application for managing users and products, to be consumed in a Frontend application."

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published