A REST API for managing vehicle records. Built with Flask and SQLite.
This API lets you create, read, update, and delete vehicle records. Each vehicle has a VIN (vehicle identification number) that uniquely identifies it.
- Python 3.8+
- pip
# install dependencies
pip install -r requirements.txt
# run the application
python app.pyThe server will start at http://localhost:5000.
GET /vehicleReturns a list of all vehicles in the database.
Example:
curl http://localhost:5000/vehiclePOST /vehicleRequest body (all fields required):
{
"vin": "ABC12345678901234",
"manufacturer_name": "toyota",
"description": "reliable sedan",
"horse_power": 200,
"model_name": "camry",
"model_year": 2023,
"purchase_price": 25000.50,
"fuel_type": "gasoline"
}Example:
curl -X POST http://localhost:5000/vehicle \
-H "Content-Type: application/json" \
-d '{"vin":"ABC12345678901234","manufacturer_name":"toyota","description":"reliable sedan","horse_power":200,"model_name":"camry","model_year":2023,"purchase_price":25000.50,"fuel_type":"gasoline"}'GET /vehicle/{vin}Example:
curl http://localhost:5000/vehicle/ABC12345678901234Note: VIN lookup is case-insensitive.
PUT /vehicle/{vin}Request body should include all fields. The VIN in the body must match the VIN in the URL.
Example:
curl -X PUT http://localhost:5000/vehicle/ABC12345678901234 \
-H "Content-Type: application/json" \
-d '{"vin":"ABC12345678901234","manufacturer_name":"toyota","description":"updated description","horse_power":250,"model_name":"camry","model_year":2023,"purchase_price":30000.00,"fuel_type":"gasoline"}'DELETE /vehicle/{vin}Example:
curl -X DELETE http://localhost:5000/vehicle/ABC12345678901234The API returns different HTTP status codes depending on what went wrong:
400 Bad Request- The JSON you sent is malformed or missing404 Not Found- The vehicle with that VIN doesn't exist422 Unprocessable Entity- Your data is invalid (missing fields, wrong types, etc.)
When there's an error, you'll get a JSON response with details:
{
"errors": ["vin must be 17 characters", "horse power must be a positive integer"]
}The API checks your data before saving:
- VIN must be exactly 17 characters
- All fields are required
- Horse power must be a positive integer
- Model year must be between 1900 and 2026
- Purchase price must be a positive number
VINs are case-insensitive and stored in uppercase.
pytest tests/test_api.py -vThe test suite includes 22 tests covering all endpoints and error cases.
vehicle-api/
├── app.py # main application and API routes
├── models.py # vehicle data model and validation
├── database.py # database setup
├── requirements.txt # python dependencies
└── tests/
└── test_api.py # test suite
The app uses SQLite with a file called vehicles.db in the project directory. It's created automatically when you first run the application.
- The VIN field is case-insensitive
- You cannot change a vehicle's VIN through the update endpoint. If you need a different VIN, delete the old record and create a new one.
- The server runs in debug mode by default. For production use, you should disable debug mode in
app.py.