The RESTful Inventory API is a small, production-ready service for tracking computers and their attributes. Built with Node.js and Express, it stores data in MySQL and offers a clean REST interface secured with HTTP basic authentication. The project emphasises simplicity and best practices, making it easy to deploy and extend.
npm installConfiguration values can be supplied via environment variables or by editing config/index.js.
| Variable | Description | Default |
|---|---|---|
DB_HOST |
MySQL host | db |
DB_USER |
MySQL user | root |
DB_PASSWORD |
MySQL password | password |
DB_NAME |
Database name | inventory |
AUTH_USER |
Basic auth username | test |
AUTH_PW |
Basic auth password | test |
PORT |
Server port | 3000 |
DEBUG |
Enable verbose logging | false |
Initialise the database using the SQL script in setup/db_setup.sql.
npm startThe API will be available at http://localhost:3000 by default.
Run the API and a MySQL instance with a single command:
docker-compose up --buildThe MySQL service initialises with setup/db_setup.sql. Stop the stack with Ctrl+C and remove containers using:
docker-compose downAll endpoints require HTTP basic authentication.
Return the full inventory sorted by id.
curl -u test:test http://localhost:3000/v1/inventoryRetrieve a single inventory item by numeric id.
curl -u test:test http://localhost:3000/v1/inventory/1Retrieve a single inventory item by hostname.
curl -u test:test http://localhost:3000/v1/inventory/hostname/PC-01Create a new inventory item. Example body:
{
"hostname": "PC-01",
"uuid": "deff0438-0776-4e75-b36d-da6eb2c0946e",
"ip": "10.0.0.5",
"os": "Windows 11",
"version": "11.2022",
"uptime": "42"
}Update an existing inventory item.
Delete an inventory item.
This project is licensed under the MIT License - see LICENSE.md for details.
Marc-André Bombeck – @MBombeck