https://github.com/suman105/rest-api-using-node
This project demonstrates RESTful functionality using Node, providing a structured way to manage customers, purchases, and shipping details.
https://github.com/suman105/rest-api-using-node
express-js javascript node-js restapi-backend
Last synced: about 2 months ago
JSON representation
This project demonstrates RESTful functionality using Node, providing a structured way to manage customers, purchases, and shipping details.
- Host: GitHub
- URL: https://github.com/suman105/rest-api-using-node
- Owner: suman105
- Created: 2022-07-08T07:54:30.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-06T09:20:10.000Z (about 1 year ago)
- Last Synced: 2025-05-30T08:35:44.327Z (about 1 year ago)
- Topics: express-js, javascript, node-js, restapi-backend
- Language: JavaScript
- Homepage:
- Size: 3.46 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# REST API for Customer, Purchase, and Shipping Management ๐๐ผ
This REST API allows you to manage customers, their purchases, and shipping details. It provides endpoints to perform CRUD operations on customers, purchase records, and shipping information.
## Features ๐
- **Customer Management**: Create, view, and fetch customer details.
- **Purchase Management**: Add purchases, view purchase records for customers.
- **Shipping Management**: Add shipping details and view shipping records associated with customers and their purchases.
- **Custom Queries**: Fetch data based on specific criteria like city and email.
## Tech Stack ๐ ๏ธ
- **Node.js**: JavaScript runtime for building server-side applications.
- **Express.js**: Web framework for Node.js to handle routing and middleware.
- **MongoDB**: NoSQL database for storing customer, purchase, and shipping data.
- **Mongoose**: ODM (Object Data Modeling) library for MongoDB.
- **Postman**: Tool for testing API endpoints.
## Installation โ๏ธ
Follow these steps to set up and run the project locally:
### 1. Clone the repository
```bash
git clone https://github.com/yourusername/REST-API-Using-Node.git
```
### 2. Navigate to the project folder and install the required dependencies:
```bash
cd REST-API-Using-Node
npm install
```
### 3. Set up environment variables
Create a `.env` file in the root of your project and add the following:
```bash
PORT=5000
MONGO_URI=
```
- PORT: The port your server will listen on (default 5000).
- MONGO_URI: Your MongoDB connection string.
### 4. Run the server
To start the server, run:
```bash
npm start
```
The server should now be running on http://localhost:5000.
## API Endpoints ๐ก
#### 1. Get All Customers ๐งโ๐คโ๐ง
- **Endpoint:** GET /customer
- Retrieves all customers.
- **Response:**
- 200 OK with an array of customers.
- 404 Not Found if no customers are found.
#### 2. Get Shipping Details by City ๐๏ธ
- **Endpoint:** GET /shipping/city
- Fetch shipping details based on the provided city.
- **Query Parameter:**
- **City:** The city name to filter customers by.
- **Response:**
- 200 OK with shipping details.
- 400 Bad Request if the City parameter is missing.
- 404 Not Found if no shipping details are found.
#### 3. Get Customer Purchases and Shipments ๐ฆ๐
- **Endpoint:** GET /customer/purchase/shipment
- Fetches purchase and shipment details for all customers.
- **Response:**
- 200 OK with customer purchase and shipment details.
- 404 Not Found if no customers or records are found.
#### 4. Get Customer Purchases ๐๏ธ
- **Endpoint:** GET /customer/purchases
- Fetches all purchase records for all customers.
- **Response:**
- 200 OK with customer purchase details.
- 404 Not Found if no customers or records are found.
#### 5. Add a New Customer ๐งโ๐ผ
- **Endpoint:** POST /customer
- Creates a new customer.
- **Request Body:**
```bash
{
"Customer_Name": "John Doe",
"Email": "john.doe@example.com",
"Mobile_Number": "1234567890",
"City": "New York"
}
```
- **Response:**
- 201 Created with the created customer details.
- 400 Bad Request if any required field is missing.
#### 6. Add a New Purchase ๐
- **Endpoint:** POST /purchase
- Creates a new purchase record for a customer.
- **Request Body:**
```bash
{
"Email": "john.doe@example.com",
"Product_Name": "Product A",
"Quantity": 2,
"Pricing": 100,
"MRP": 120
}
```
- **Response:**
- 201 Created with the created purchase details.
- 400 Bad Request if the customer is not found or the pricing is greater than the MRP.
#### 7. Add a New Shipping Record ๐
- **Endpoint:** POST /shipping
- Creates a new shipping record for a customer.
- **Request Body:**
```bash
{
"Email": "john.doe@example.com",
"Address": "1234 Elm Street",
"City": "New York",
"Pincode": "10001"
}
```
- **Response:**
- 201 Created with the created shipping details.
- 400 Bad Request if the request body is incomplete.
#### 8. Get All Customers with City Information ๐
- **Endpoint:** GET /details
- Fetches all customers along with their city information.
- **Response:**
- 200 OK with customer details.
- 404 Not Found if no customers are found.
## Testing the API ๐งช
You can use Postman or Insomnia to test the API by making requests to the endpoints listed above. Simply enter the appropriate URL and HTTP method (GET, POST).
## โญ **Show Some Support**
If this repository helps you, consider starring โญ it on GitHub. Your support encourages further improvements and new additions!
๐ฉ Feel free to open an issue if you have questions or suggestions.
๐ Happy Coding & DSA Mastery! ๐