Skip to content

This Azure-based API is designed for managing vehicle registrations for a vehicle show meetup. It supports operations like user registration, vehicle number validation, and user management with features like filtering, pagination, and timestamps. Built using Node.js, Express, and MongoDB.

Notifications You must be signed in to change notification settings

A-Samod/azure-vehicle-show-registration-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vehicle Show Registration API

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.

Features

  • 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

Prerequisites

Make sure you have the following installed:

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/vehicle-show-registration-api.git
    cd vehicle-show-registration-api
  2. Install dependencies:

    npm install
  3. Install Azure Functions Core Tools:

    npm install -g azure-functions-core-tools@4 --unsafe-perm true
  4. 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"
      }
    }
  5. Ensure MongoDB is running locally or update the MONGO_URI to point to your MongoDB instance.

Running the Project Locally

To run the Azure Functions app locally:

  1. Start the Azure Functions app:

    func start
  2. The API will be running on http://localhost:7071. Use Postman or cURL to interact with the API endpoints.

API Endpoints

Create User (Vehicle Registration)

  • URL: /api/CreateUser

  • Method: POST

  • Request Body:

    {
      "user_name": "John Doe",
      "nic": "987654321V",
      "mobile": "0712345678",
      "vehicle_no": "WPABC1234",
      "vehicle_model": "Toyota Corolla"
    }

Get User By ID

  • URL: /api/GetUserById/{id}
  • Method: GET

Get All Users with Pagination

  • URL: /api/GetUsers
  • Method: GET
  • Query Params: ?page=1&limit=10

Update User

  • URL: /api/UpdateUser/{id}
  • Method: PUT
  • Request Body: Fields to update.

Delete User

  • URL: /api/DeleteUser/{id}
  • Method: DELETE

Validate Vehicle Number

  • URL: /api/ValidateVehicle

  • Method: POST

  • Request Body:

    {
      "vehicle_no": "WPABC1234"
    }

Testing the API

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"
}'

Running Swagger Locally

The project includes Swagger documentation for easy API testing.

  1. Start the Azure Functions locally using the following command:

    func start
  2. Navigate to http://localhost:7071/api-docs in your browser to view the Swagger UI and test the API endpoints.

Deployment

To deploy the functions to Azure, follow these steps:

  1. # to Azure:

    az login
  2. 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>
  3. Deploy your app:

    func azure functionapp publish <function-app-name>

Folder Structure

/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

License

This project is licensed under the MIT License.

About

This Azure-based API is designed for managing vehicle registrations for a vehicle show meetup. It supports operations like user registration, vehicle number validation, and user management with features like filtering, pagination, and timestamps. Built using Node.js, Express, and MongoDB.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published