This project implements a basic vending machine API with TypeScript, Node.js, and Express.
Method | Route | Description |
---|---|---|
GET | /maintenanceUser/products | Get all products available. |
GET | /maintenanceUser/products/{productId} | Get a product by ID. |
POST | /maintenanceUser/createProduct | Create a new product. |
PUT | /maintenanceUser/setPrice/{productId} | Set the price for a product. |
PUT | /maintenanceUser/adjustQuantity/{productId} | Adjust the quantity of a product. |
DELETE | /maintenanceUser/deleteProduct/{productId} | Delete a product by ID. |
GET | /maintenanceUser/getCoins | Get all coins available in the machine. |
POST | /maintenanceUser/createCoins | Create coins. |
PUT | /maintenanceUser/updateCoins | Update coins available in the machine. |
DELETE | /maintenanceUser/deleteCoin/{coinValue} | Delete a coin by coin value. |
Method | Route | Description |
---|---|---|
GET | /regularUser/products | Get all products available. |
GET | /regularUser/products/{productId} | Get a product by ID. |
POST | /regularUser/buyProduct | Buy a product by specifying product slot and coins. |
- Node.js (https://nodejs.org/)
- npm (comes with Node.js)
- Navigate to project folder
cd vending-machine-api
- Install the dependencies:
npm install
Run the app:
For production:
npm start
For development:
npm run dev
This setup assumes you have tsc (TypeScript compiler) and nodemon installed globally or as devDependencies. If not, you can install them using:
npm install -g typescript nodemon
The API will be available at http://localhost:3000.
API documentation is generated using Swagger and can be accessed at http://localhost:3000/api-docs.
For tests with coverage
npm run test
Viewing Coverage Report:
open coverage/lcov-report/index.html