A Simple MERN Stack API using Express JS, Mongo DB for Beginners
This is a Node.js application built with Express and MongoDB for managing vendors and users. The API allows for creating, reading, updating, and deleting vendors and users.
- Vendor Management: Create, read, update, and delete vendor information.
- User Management: Create, read, update, and delete user information.
- MongoDB Integration: Uses MongoDB for data storage.
- Express Framework: Built with Express for handling HTTP requests.
-
Clone the repository:
git clone https://github.com/your-username/vendor-user-management-api.git cd vendor-user-management-api
-
Install dependencies:
npm install
-
Configure MongoDB connection:
- Replace
YOUR_CONNECTION_STRING
inapp.js
with your actual MongoDB connection string.
- Replace
-
Start the server:
npm start
- The server will start on
http://localhost:8080
.
- The server will start on
express.json()
: Middleware to parse JSON bodies from HTTP requests.
- The MongoDB connection string is configured in the
app.js
file. Update themongoDbConnectionString
variable with your MongoDB connection string.
- Endpoint:
GET /vendors
- Description: Retrieve all vendors from the database.
- Response:
[ { "from": "Location A", "location": "City A", "vendor": "Vendor A", "price": 100 }, ... ]
- Endpoint:
GET /vendors/:id
- Description: Retrieve a vendor by its ID.
- Response:
{ "from": "Location A", "location": "City A", "vendor": "Vendor A", "price": 100 }
- Endpoint:
POST /createvendor
- Description: Add a new vendor to the database.
- Request Body:
{ "from": "Location A", "location": "City A", "vendor": "Vendor A", "price": 100 }
- Response:
{ "from": "Location A", "location": "City A", "vendor": "Vendor A", "price": 100, "_id": "60c72b2f9b1d8c001f0e4e2e" }
- Endpoint:
PUT /updatevendor/:id
- Description: Update an existing vendor by its ID.
- Request Body:
{ "from": "Location B", "location": "City B", "vendor": "Vendor B", "price": 200 }
- Response:
"60c72b2f9b1d8c001f0e4e2e Updated Successfully."
- Endpoint:
DELETE /deletevendor/:tag
- Description: Delete a vendor by a specific tag.
- Request Query Parameters:
id
: Vendor ID to be deleted.
- Response:
"60c72b2f9b1d8c001f0e4e2e Deleted Successfully."
- Endpoint:
GET /users
- Description: Retrieve all users from the database.
- Response:
[ { "name": "User A", "phone": 1234567890, "gender": "Male" }, ... ]
- Endpoint:
GET /users/:id
- Description: Retrieve a user by its ID.
- Response:
{ "name": "User A", "phone": 1234567890, "gender": "Male" }
- Endpoint:
POST /createuser
- Description: Add a new user to the database.
- Request Body:
{ "name": "User A", "phone": 1234567890, "gender": "Male" }
- Response:
{ "name": "User A", "phone": 1234567890, "gender": "Male", "_id": "60c72b2f9b1d8c001f0e4e2e" }
- Endpoint:
PUT /updateuser/:id
- Description: Update an existing user by its ID.
- Request Body:
{ "name": "User B", "phone": 9876543210, "gender": "Female" }
- Response:
"60c72b2f9b1d8c001f0e4e2e Updated Successfully."
- Endpoint:
DELETE /deleteuser/:id
- Description: Delete a user by ID.
- Response:
"60c72b2f9b1d8c001f0e4e2e Deleted Successfully."
This project is licensed under the MIT License.
Feel free to adjust any sections as necessary to fit your project specifics.