Skip to content

Kashish3009/CustomerInfo.API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CustomerInfo API v1

Live on: https://api-customerinfo-eastus-001.azurewebsites.net/swagger/index.html

This is a .NET 7 (core) based web APIs project that renders a scenario to store the customer information like FirstName, LastName, Email, Phone.

Operations supported:

1. Create a Customer record
2. Fetch all customers records 
3. Fetch a customer by Id 
4. Update customer record
5. Delete a customer record by Id

Demo

CustomerInfo APIs

API Reference

Get all customers

  GET /api/customers
Query Parameter Type Description
filterOn string optional - field to filter on
filterQuery string optional - value of the field
sortBy string optional - field name
isAscending bool optional - 'true' or 'false'
pageNumber int optional - page number to fetch
pageSize int optional - no. of records in one page

Example: /api/customers?filterOn=FirstName&filterQuery=Kashish&sortBy=LastName&isAscending&pageNumber=1&pageSize=10

Get customer by id

  GET /api/customers/{id}
Parameter Type Description
id int Required - Id of item to fetch

Create customer

  POST /api/customers

Body Schema:

{ "firstName": "string", "lastName": "string", "email": "[email protected]", "phoneNumber": "string" }

Update customer

  PUT /api/customers/{id}
Parameter Type Description
FirstName string Required - first name of the customer
LastName string Required - last name of the customer
Email string Required - email id of the customer
PhoneNumber string Required - phone number of the customer

Body Schema:

{ "firstName": "string", "lastName": "string", "email": "[email protected]", "phoneNumber": "string" }

Delete customer

  DELETE /api/customers/{id}
Parameter Type Description
id int Required - Id of customer to be deleted

Tech Stack

1. .NET core 7
2. Web API
3. C#
4. Azure
5. MS SQl Server database
6. Github
7. Swagger UI
8. Visual Studio 2022 IDE community edition

Cloning the code

Follow below steps sequentially for cloning the source code to your local workspace:

Using cmd:

Step 1: Open Git Bash.

Step 2: Change the current working directory to the location where you want the cloned directory

Step 3: Copy below command in the git bash and hit enter.

    git clone https://github.com/Kashish3009/CustomerInfo.API.git

image

Using Visual Studio 2022 UI

To clone directly using Visual Studio 2022, open Visual Studio 2022 and

    1. Go to "File", 
    2. Click on "Clone Repository", 
    3. Copy below URL
    https://github.com/Kashish3009/CustomerInfo.API.git
    5. Paste the URL in the "Repository Location" box.
    6. Click on "Clone" button.

image

Reference: https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository

Run Locally

Clone the project

  git clone https://github.com/Kashish3009/CustomerInfo.API.git

Navigate to the project directory in bin folder where you have cloned the project:

  cd <my-project>

Start the server

   dotnet customerInfo.API.dll

Open the browser and navigate to the path where your server is listening on. Example:

  http://localhost:5000/swagger/index.html

image

image

Deployment to Azure cloud

After cloning the source code in local environment, follow steps below to deploy in Azure cloud:

Pre-requisites:

    1. Azure Account: If you don't have an Azure account, you can sign up for a free account here.
    2. Visual Studio 2022: Ensure you have Visual Studio 2022 installed on your machine.

Step 1: Create an Azure Account and Activate Subscription.

    1. Sign Up for Azure: Go to Azure Portal and sign up for a new Azure account.   
    2. Activate Subscription: Once signed in, activate your Azure subscription.

Step 2: Create a Resource Group in Azure UI

    1. Navigate to the Azure Portal: Open the Azure Portal.
    2. To create a Resource group, In the left sidebar, click on "Resource groups."
    3. Click the "+ Add" button.
    4. Fill in the required details (Name, Region etc.).
    4. Click "Review + create" and then "Create."

Step 3: Create App Service in Azure UI

    1. Navigate to Resource Group: In the Azure Portal, go to your newly created resource group.
    2. To create an App Service, Click on "+ Add."
    3. Search for "App Service" and select it.
    4. Click "Create."
    5. Fill in the required details (App name, Subscription, Resource group, OS, etc.).
    6. Click "Review + create" and then "Create."

Step 4: Add SQL Server DB to Resource Group

    1. Navigate to Resource Group: In the Azure Portal, go to your resource group.
    2. Add SQL Server: Click on "+ Add."
    3. Search for "SQL Database" and select it.
    4. Click "Create."
    5. Fill in the required details (Database name, Server, Pricing tier, etc.).
    6. Click "Review + create" and then "Create."

Step 5: Add SQL Database to SQL Server

    1. Navigate to SQL Server: In the Azure Portal, go to your SQL Server instance.
    2. Add a Database: In the left sidebar, under Settings, click on "Databases."
    3. Click "+ Add" and fill in the required details.
    4. Click "Review + create" and then "Create."

Step 6: Add Local IP Address to Networking in Azure SQL Server

    1. Navigate to SQL Server: In the Azure Portal, go to your SQL Server instance.
    2. Configure Firewall Rules: In the left sidebar, under Settings, click on "Firewalls and virtual networks."
    3. Add the IP address range of your local SQL Server to the allowed IP addresses.
    4. Follow the steps to connect local SQl Server to Azure SQl DB as per reference section "Connect SSMS to Azure SQl DB".
    5. You could run the DBInsertionsScript.sql as in code repo to insert the sample data to the DB.

Step 7: Publish API from Visual Studio IDE

    1. Open your .NET Core 7 Web API project in Visual Studio 2022 you cloned after following "cloning" section.
    2. Right-Click on Project: Right-click on your project in Solution Explorer.
    3. Select "Publish."
    4. Publish to Azure: Choose "Azure" as the target.
    5. Click "Create New" to configure the connection.
    6. Follow the wizard to configure your Azure App Service.
    7. Click "Publish" to deploy your API to Azure.

image

Step 8: Verify Deployment

    1. Check App Service: Go to the Azure Portal.
    2. Navigate to your App Service.
    3. In the left sidebar, click on "Overview" to get the URL.

image

Test the API: Use tools like Postman, curL etc. to test your API using the Azure App Service URL.

Congratulations!! You have successfully deployed customersInfo API to Azure App Service with an Azure SQL Database.

References

Install .NET 7: https://dotnet.microsoft.com/en-us/download/dotnet/7.0

Download Visual Studio 2022 community edition: https://visualstudio.microsoft.com/vs/community/

Download and install SQL Server: https://www.microsoft.com/en-in/sql-server/sql-server-downloads

Create Azure account: https://azure.microsoft.com/en-in/free

Create Azure Resource group: https://techcommunity.microsoft.com/t5/startups-at-microsoft/step-by-step-guide-creating-an-azure-resource-group-on-azure/ba-p/3792368

Create SQl Server DB in Azure: https://learn.microsoft.com/en-us/azure/azure-sql/database/single-database-create-quickstart?view=azuresql&tabs=azure-portal

Connect SSMS to Azure SQl DB: https://learn.microsoft.com/en-us/azure/azure-sql/database/connect-query-ssms?view=azuresql

Publish .NET Core Web API to Azure using Visual Studio 2022 IDE: https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-webapp-using-vs?view=aspnetcore-8.0

Deploy .NET Core and Azure SQL DB in Azure: https://learn.microsoft.com/en-us/azure/app-service/tutorial-dotnetcore-sqldb-app

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published