Skip to content

Pirate-Emperor/Trolley-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trolley API

This repository contains a RESTful API built with Express.js and MySQL for managing a shop's inventory. The API supports CRUD (Create, Read, Update, Delete) operations on inventory items.

📋 Table of Contents

⚡️ Features

  • Create, Read, Update, and Delete inventory items.
  • Validate request bodies to ensure data integrity.
  • Check for duplicate products before adding to the inventory.
  • Fetch inventory items by ID or name.
  • Implement pagination for retrieving large datasets.
  • Error handling for invalid requests and server errors.

⚙️ Technologies Used

  • Node.js - JavaScript runtime for server-side programming.
  • Express.js - Web framework for building APIs.
  • MySQL - Relational database for storing inventory data.
  • Sequelize - ORM for interacting with the MySQL database.
  • Joi - Schema description language and data validator for JavaScript.
  • dotenv - Module to load environment variables from a .env file.

🎯 API Endpoints

The following endpoints are available:

Method Endpoint Description
POST /shop/inventory Add a new product to the inventory.
GET /shop/inventory/all Retrieve all products from the inventory.
GET /shop/inventory/:id Retrieve a product by its ID.
GET /shop/inventory/name/:name Retrieve a product by its name.
PUT /shop/inventory/:id Update a product by its ID.
DELETE /shop/inventory/:id Delete a product by its ID.

🚀 Example Request

Creating a new inventory item:

POST /shop/inventory
Content-Type: application/json

{
  "product_name": "Sample Product",
  "product_quantity": 10,
  "product_price": 100,
  "product_category": "Electronics",
  "product_description": "A sample product description."
}

Getting All Inventory Items:

GET /shop/inventory/all

🔗 Installation

1. Clone the repository:

git clone https://github.com/Pirate-Emperor/Trolley_API

2. Navigate to the project directory:

cd Trolley_API

3. Install Dependencies:

npm install

4. Set up the database:

  • Create a MySQL database for the inventory.
  • Update your database connection settings in the Sequelize configuration.

5. Create a .env file:

Create a .env file in the root directory and add your database credentials:

DB_HOST=localhost
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=your_db_name

6. Run the application:

npm start

💡 Usage

You can test the API using tools like Postman or cURL. Make sure to send requests with the appropriate HTTP methods and payloads as described in the API endpoints section. I have included a Postman collection in the postman folder for your convenience.

🧪 Testing

To run tests for this API, you can use tools like Mocha and Chai. Here’s how to run the tests:

  1. Install the testing dependencies:
npm install --save-dev mocha chai
  1. Create a test directory and add your test files.

  2. Run the tests:

npx mocha test

🤝 Contributing

Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request. Please follow these steps:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

🎉 Acknowledgments

  • Express.js - For making API development easy.
  • Sequelize - For providing a simple ORM for MySQL.
  • Joi - For schema validation.
  • Postman - For testing APIs effortlessly.

License

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

Author

Pirate-Emperor

Twitter Discord LinkedIn

Reddit Medium


About

Trolley API is a RESTful API built with Express.js and MySQL for managing a shop's inventory. It supports CRUD operations, validates data integrity, and checks for duplicate products, making inventory management efficient and reliable.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors