Skip to content

PasinduOG/REST-Grillmaster-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

REST-Grillmaster-API πŸ”πŸ”₯

License: MIT Node.js Version MongoDB Live Demo

A comprehensive RESTful API for managing a grill restaurant's menu system. Built with Node.js, Express, and MongoDB, this API provides complete CRUD operations for managing burgers, sides, and drinks.

🌐 Live API: https://rest-grillmaster-api.vercel.app/

πŸ“‹ Table of Contents

✨ Features

  • Complete CRUD Operations for Burgers, Sides, and Drinks
  • MongoDB Integration with Mongoose ODM
  • CORS Support for cross-origin requests
  • Input Validation with Mongoose schemas
  • Error Handling with descriptive error messages
  • Timestamps for all menu items (createdAt, updatedAt)
  • Availability Tracking for inventory management
  • RESTful Architecture following industry best practices
  • Unified Endpoint to retrieve all menu items at once
  • ES6+ Modules with modern JavaScript syntax
  • Production Ready with environment-based configuration
  • Deployed & Live on Vercel for instant access

πŸš€ Technologies

πŸ“¦ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v14.0.0 or higher)
  • npm (v6.0.0 or higher)
  • MongoDB Atlas Account or local MongoDB instance

πŸ”§ Installation

  1. Clone the repository:
git clone https://github.com/PasinduOG/REST-Grillmaster-API.git
cd REST-Grillmaster-API
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory:
# MongoDB Configuration
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/<database>?retryWrites=true&w=majority

# Server Configuration
PORT=3000

# CORS Configuration
ALLOWED_ORIGIN=http://localhost:3000

Replace:

  • <username> - Your MongoDB Atlas username
  • <password> - Your MongoDB Atlas password (URL-encoded if contains special characters)
  • <database> - Your database name

βš™οΈ Configuration

MongoDB Atlas Setup

  1. Create a MongoDB Atlas account at mongodb.com/cloud/atlas
  2. Create a new cluster
  3. Add a database user with read/write permissions
  4. Whitelist your IP address in Network Access
  5. Get your connection string from Connect > Connect your application

CORS Configuration

The API supports CORS with configurable origins. Update ALLOWED_ORIGIN in .env for your frontend URL.

πŸƒ Running the Application

Development Mode (with auto-reload):

npm run dev

Production Mode:

npm start

The API will be available at: http://localhost:3000

Console output:

βœ… MongoDB connected successfully
Server listening to http://localhost:3000

πŸ“‘ API Endpoints

πŸ” Burgers

Method Endpoint Description Auth
POST /item/burger/add Add a new burger No
GET /item/burger/all Get all burgers No
GET /item/burger/find/:id Get burger by ID No
PUT /item/burger/update/:id Update burger by ID No
DELETE /item/burger/remove/:id Delete burger by ID No

πŸ₯€ Drinks

Method Endpoint Description Auth
POST /item/drink/add Add a new drink No
GET /item/drink/all Get all drinks No
GET /item/drink/find/:id Get drink by ID No
PUT /item/drink/update/:id Update drink by ID No
DELETE /item/drink/remove/:id Delete drink by ID No

🍟 Sides

Method Endpoint Description Auth
POST /item/side/add Add a new side No
GET /item/side/all Get all sides No
GET /item/side/find/:id Get side by ID No
PUT /item/side/update/:id Update side by ID No
DELETE /item/side/remove/:id Delete side by ID No

πŸ“¦ All Items

Method Endpoint Description Auth
GET /item/all Get all menu items (burgers, sides, drinks) No

πŸ§ͺ Testing the API

Using cURL

Get all items:

curl https://rest-grillmaster-api.vercel.app/item/all

Add a new burger:

curl -X POST https://rest-grillmaster-api.vercel.app/item/burger/add \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Bacon Deluxe",
    "category": "Premium",
    "price": 12.99,
    "qty": 30,
    "image_url": "https://example.com/bacon-deluxe.jpg"
  }'

Update a burger:

curl -X PUT https://rest-grillmaster-api.vercel.app/item/burger/update/YOUR_ITEM_ID \
  -H "Content-Type: application/json" \
  -d '{"price": 13.99, "qty": 25}'

Delete a burger:

curl -X DELETE https://rest-grillmaster-api.vercel.app/item/burger/remove/YOUR_ITEM_ID

Using Postman

  1. Import the API endpoints from the root endpoint
  2. Create a new collection named "GrillMaster API"
  3. Add requests for each endpoint
  4. Set headers: Content-Type: application/json
  5. Add request bodies for POST/PUT operations

Using Thunder Client (VS Code)

  1. Install Thunder Client extension
  2. Create new request
  3. Enter endpoint URL
  4. Select HTTP method
  5. Add JSON body for POST/PUT requests
  6. Send request

Using JavaScript Fetch API

// Get all burgers
fetch('https://rest-grillmaster-api.vercel.app/item/burger/all')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

// Add a new burger
fetch('https://rest-grillmaster-api.vercel.app/item/burger/add', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Spicy Chicken Burger',
    category: 'Chicken',
    price: 10.99,
    qty: 40,
    image_url: 'https://example.com/spicy-chicken.jpg'
  })
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

πŸ“ Request/Response Examples

Add a Burger

Request:

POST /item/burger/add
Content-Type: application/json

{
  "name": "Classic Cheeseburger",
  "category": "Classic",
  "price": 9.99,
  "qty": 50,
  "image_url": "https://example.com/images/classic-burger.jpg"
}

Response (201 Created):

{
  "message": "Burger successfully added!",
  "added": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Classic Cheeseburger",
    "category": "Classic",
    "price": 9.99,
    "qty": 50,
    "image_url": "https://example.com/images/classic-burger.jpg",
    "is_available": true,
    "createdAt": "2025-12-19T10:30:00.000Z",
    "updatedAt": "2025-12-19T10:30:00.000Z"
  }
}

Get All Items

Request:

GET /item/all

Response (200 OK):

{
  "message": "15 items found!",
  "items": [
    {
      "_id": "507f1f77bcf86cd799439011",
      "name": "Classic Cheeseburger",
      "category": "Classic",
      "price": 9.99,
      "qty": 50,
      "image_url": "https://example.com/images/classic-burger.jpg",
      "is_available": true,
      "createdAt": "2025-12-19T10:30:00.000Z",
      "updatedAt": "2025-12-19T10:30:00.000Z"
    }
  ]
}

Update a Burger

Request:

PUT /item/burger/update/507f1f77bcf86cd799439011
Content-Type: application/json

{
  "price": 10.99,
  "qty": 45
}

Response (200 OK):

{
  "message": "Burger updated successfully",
  "burger": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Classic Cheeseburger",
    "category": "Classic",
    "price": 10.99,
    "qty": 45,
    "image_url": "https://example.com/images/classic-burger.jpg",
    "is_available": true,
    "createdAt": "2025-12-19T10:30:00.000Z",
    "updatedAt": "2025-12-19T11:15:00.000Z"
  }
}

Delete a Burger

Request:

DELETE /item/burger/remove/507f1f77bcf86cd799439011

Response (200 OK):

{
  "message": "Burger removed successfully!",
  "removed": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Classic Cheeseburger",
    "category": "Classic",
    "price": 10.99,
    "qty": 45,
    "image_url": "https://example.com/images/classic-burger.jpg",
    "is_available": true
  }
}

πŸ—‚οΈ Data Models

Burger Schema

{
  name: String (required),
  category: String (required),
  price: Number (required, min: 0),
  qty: Number (required, min: 0),
  image_url: String (required),
  is_available: Boolean,
  timestamps: true
}

Drink Schema

{
  name: String (required),
  category: String (required),
  price: Number (required, min: 0),
  qty: Number (required, min: 0),
  image_url: String (required),
  is_available: Boolean,
  timestamps: true
}

Side Schema

{
  name: String (required),
  category: String (required),
  price: Number (required, min: 0),
  qty: Number (required, min: 0),
  image_url: String (required),
  is_available: Boolean,
  timestamps: true
}

πŸ“ Project Structure

REST-Grillmaster-API/
β”œβ”€β”€ config/
β”‚   └── mongoose.js           # MongoDB connection configuration
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ allItem.controller.js # Controller for all items endpoint
β”‚   β”œβ”€β”€ burgers.Controller.js # Burger CRUD operations
β”‚   β”œβ”€β”€ drinks.controller.js  # Drink CRUD operations
β”‚   └── sides.controller.js   # Side CRUD operations
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ burger.model.js       # Burger schema definition
β”‚   β”œβ”€β”€ drink.model.js        # Drink schema definition
β”‚   └── side.model.js         # Side schema definition
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ allItem.routes.js     # All items routes
β”‚   β”œβ”€β”€ burger.routes.js      # Burger routes
β”‚   β”œβ”€β”€ drink.routes.js       # Drink routes
β”‚   └── side.routes.js        # Side routes
β”œβ”€β”€ .env                      # Environment variables (create this)
β”œβ”€β”€ .gitignore               # Git ignore file
β”œβ”€β”€ app.js                   # Main application entry point
β”œβ”€β”€ package.json             # Project dependencies and scripts
└── README.md               # Project documentation

⚠️ Error Handling

The API returns appropriate HTTP status codes and error messages:

Status Codes

Code Description
200 Success
201 Created successfully
404 Resource not found
405 Resource already exists
500 Internal server error

Error Response Format

{
  "message": "Error description",
  "error": "Detailed error message"
}

οΏ½ Deployment

This API is deployed on Vercel and is publicly accessible.

Deploy Your Own Instance

Deploy to Vercel

  1. Fork this repository

  2. Sign up/Login to Vercel

  3. Import your forked repository:

    • Click "Add New Project"
    • Select your GitHub repository
    • Configure project settings
  4. Add Environment Variables:

    • MONGODB_URI: Your MongoDB Atlas connection string
    • PORT: 3000 (or your preferred port)
    • ALLOWED_ORIGIN: Your frontend URL
  5. Deploy!

    • Vercel will automatically deploy your API
    • You'll receive a production URL

Deploy to Other Platforms

Heroku:

# Login to Heroku
heroku login

# Create new app
heroku create your-app-name

# Set environment variables
heroku config:set MONGODB_URI=your_mongodb_uri
heroku config:set PORT=3000
heroku config:set ALLOWED_ORIGIN=your_frontend_url

# Deploy
git push heroku main

Railway:

# Install Railway CLI
npm install -g @railway/cli

# Login and initialize
railway login
railway init

# Add environment variables in Railway dashboard
# Deploy
railway up

Render:

  1. Create new Web Service
  2. Connect your GitHub repository
  3. Add environment variables
  4. Deploy

Production Checklist

  • Set secure MongoDB credentials
  • Configure CORS for your domain
  • Add rate limiting middleware
  • Implement authentication (if needed)
  • Set up monitoring and logging
  • Configure custom domain (optional)
  • Enable HTTPS

οΏ½πŸ› Troubleshooting

MongoDB Connection Error (ENOTFOUND)

Error:

❌ MongoDB connection error: Error: querySrv ENOTFOUND _mongodb._tcp.cluster.mongodb.net

Solutions:

  1. Verify your MONGODB_URI format in .env
  2. Ensure the connection string starts with mongodb+srv://
  3. Check your MongoDB Atlas username and password
  4. Whitelist your IP address in MongoDB Atlas Network Access
  5. URL-encode special characters in your password

Port Already in Use

Error:

Error: listen EADDRINUSE: address already in use :::3000

Solutions:

  1. Change the PORT in .env file
  2. Kill the process using port 3000:
    # Windows
    netstat -ano | findstr :3000
    taskkill /PID <PID> /F

Items Not Found (404)

Possible Causes:

  • Collections are empty in your database
  • Incorrect collection names
  • Database connection issues

Solution:

  • Add items using POST endpoints
  • Verify collections exist in MongoDB Atlas

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/AmazingFeature
  3. Commit your changes
    git commit -m 'Add some AmazingFeature'
  4. Push to the branch
    git push origin feature/AmazingFeature
  5. Open a Pull Request

Coding Standards

  • Use ES6+ syntax
  • Follow REST API naming conventions
  • Write descriptive commit messages
  • Add error handling for all async operations
  • Test all endpoints before submitting PR

πŸ“„ License

This project is licensed under the MIT License.

πŸ‘€ Author

Pasindu Owa Gamage

🌟 Star This Repository

If you find this project useful, please consider giving it a ⭐ on GitHub!

πŸ™ Acknowledgments


πŸ“ž Support

If you have any questions or need help, please:

πŸ”— Useful Links


Made with ❀️ by Pasindu OG

Happy Coding! πŸš€

About

A comprehensive RESTful API for managing a grill restaurant's menu system. Built with Node.js, Express, and MongoDB, this API provides complete CRUD operations for managing burgers, sides, and drinks.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors