This Vehicle management service API supports CRUD operations for an inventory of vehicles.
- Add a new vehicle to the inventory.
- Retrieve a list of all current vehicles in the inventory.
- Update the information of an existing vehicle.
- Delete a vehicle from the inventory.
- Clone the GitHub repository to run it on your local machine. Then navigate to the repository directory:
git clone <repository-url>
cd <repository-url>
- Install required dependencies using npm:
npm install
- Start the server. By default the server runs on port 8080:
node server.js
This section will describe the current available endpoints:
- Get all vehicles
- Retrieve a list of all vehicles in the inventory.
- /vehicles endpoint
- GET request
- Example Response:
[
{ "id": 1, "make": "Toyota", "model": "Camry", "year": 2021, "trim": "LE" },
{ "id": 2, "make": "Honda", "model": "Civic", "year": 2020, "trim": "EX" }
]
- Add a vehicle
- Add a new vehicle to the inventory.
- /vehicles endpoint
- POST request
- Example Request Body:
{ "make": "Mazda", "model": "CX-5", "year": 2019, "trim": "Sport" }
- Example Response:
{ "id": 3, "make": "Mazda", "model": "CX-5", "year": 2019, "trim": "Sport" }
- Update a vehicle
- Update an existing vehicle in the inventory.
- /vehicles/{id} endpoint
- PUT request
- Example Request Body:
{ "make": "Mazda", "model": "CX-5", "year": 2019, "trim": "Grand Touring" }
- Example Response:
{
"id": 3,
"make": "Mazda",
"model": "CX-5",
"year": 2019,
"trim": "Grand Touring"
}
- Delete a vehicle
- Delete an existing vehicle from the inventory.
- /vehicles/{id} endpoint
- DELETE request
The API currently reads and writes data to a local JSON file for simplicity. In the future, integrating a database such as MySQL would be more applicable. The addition of a database will promote a more maintainable and scalable API, which is more useful for a real production environment.