This project is an Azure Functions-based API that allows users to register their vehicles for a vehicle show meetup. It includes features for creating, updating, retrieving, and deleting vehicle registrations, as well as validating vehicle numbers.
- Create a new vehicle registration
- Retrieve vehicle registrations by ID
- Update vehicle details
- Delete a vehicle registration
- Validate if a vehicle number already exists
- Pagination support for retrieving multiple vehicle registrations
Make sure you have the following installed:
- Node.js (v14 or v16 recommended)
- Azure Functions Core Tools (v4 or later)
- MongoDB for database storage
-
Clone the repository:
git clone https://github.com/your-username/vehicle-show-registration-api.git cd vehicle-show-registration-api
-
Install dependencies:
npm install
-
Install Azure Functions Core Tools:
npm install -g azure-functions-core-tools@4 --unsafe-perm true
-
Create a
local.settings.json
file in the root of your project with the following content:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "MONGO_URI": "mongodb://localhost:27017/vehicleshow", "FUNCTIONS_WORKER_RUNTIME": "node" } }
-
Ensure MongoDB is running locally or update the
MONGO_URI
to point to your MongoDB instance.
To run the Azure Functions app locally:
-
Start the Azure Functions app:
func start
-
The API will be running on
http://localhost:7071
. Use Postman or cURL to interact with the API endpoints.
-
URL:
/api/CreateUser
-
Method:
POST
-
Request Body:
{ "user_name": "John Doe", "nic": "987654321V", "mobile": "0712345678", "vehicle_no": "WPABC1234", "vehicle_model": "Toyota Corolla" }
- URL:
/api/GetUserById/{id}
- Method:
GET
- URL:
/api/GetUsers
- Method:
GET
- Query Params:
?page=1&limit=10
- URL:
/api/UpdateUser/{id}
- Method:
PUT
- Request Body: Fields to update.
- URL:
/api/DeleteUser/{id}
- Method:
DELETE
-
URL:
/api/ValidateVehicle
-
Method:
POST
-
Request Body:
{ "vehicle_no": "WPABC1234" }
You can test the API locally using:
- Postman to send HTTP requests to your local Azure Functions.
cURL
from the command line.
For example, to create a user with cURL:
curl -X POST http://localhost:7071/api/CreateUser -H "Content-Type: application/json" -d '{
"user_name": "John Doe",
"nic": "987654321V",
"mobile": "0712345678",
"vehicle_no": "WPABC1234",
"vehicle_model": "Toyota Corolla"
}'
The project includes Swagger documentation for easy API testing.
-
Start the Azure Functions locally using the following command:
func start
-
Navigate to
http://localhost:7071/api-docs
in your browser to view the Swagger UI and test the API endpoints.
To deploy the functions to Azure, follow these steps:
-
# to Azure:
az login
-
Create a new function app:
az functionapp create --resource-group <resource-group> --consumption-plan-location <location> --runtime node --runtime-version 14 --functions-version 3 --name <function-app-name> --storage-account <storage-account-name>
-
Deploy your app:
func azure functionapp publish <function-app-name>
/vehicle-show-registration-api
├── /src
│ ├── /functions
│ │ └── CreateUser.js
│ │ └── GetUserById.js
│ │ └── GetUsers.js
│ │ └── UpdateUser.js
│ │ └── DeleteUser.js
│ │ └── ValidateVehicle.js
│ ├── /shared
│ │ └── userService.js
│ ├── /models
│ │ └── userModel.js
├── local.settings.json
├── host.json
└── package.json
This project is licensed under the MIT License.