This is a basic CRUD application for managing users and products, designed as part of a Frontend course.
- USERS:
api/v1/users
- PRODUCTS:
api/v1/products
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.
To get started with this project locally, follow these steps:
- Node.js (v14 or higher)
- MongoDB (or use MongoDB Atlas for a cloud database)
- Git (for version control)
-
Clone the repository:
git clone https://github.com/dev-madepozo/cibertec-crud-users.git
-
Navigate into the project directory:
cd cibertec-crud-users
-
Install the dependencies:
npm install
-
Create a
.env
file in the root directory and add your MongoDB connection string:MONGODB_URI=your_mongodb_connection_string PORT=8080
-
Start the development server:
npm dev
-
The API will now be running on http://localhost:8080.
To test the API, you can use tools like Postman or cURL.
-
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.
The following API endpoints are available for 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 } }
- 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 } ]
- 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 }
-
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 } }
- Description: Delete a user by ID.
- Response:
{ "message": "User deleted successfully" }
The following API endpoints are available for 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 } }
- 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 } ]
- 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 } ]
- 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 }
-
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 } }
- Description: Delete a product by ID.
- Response:
{ "message": "Product deleted successfully" }
Feel free to fork this project and submit pull requests. Contributions are welcome to help improve this API.
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes and commit them (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
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.