Wednesday, February 16, 2022

Azure Series - Azure App Service and .Net core Web API - Create and deploy to Azure Cloud

Introduction:

Azure App Service is a fully managed platform that enables developers to build, host, and scale web applications effortlessly. In this article, we will walk you through the process of creating an Azure App Service and deploying a .NET Core Web API to it. Additionally, we'll provide a sample request to demonstrate how to use the deployed API.

Prerequisites:

  1. An Azure account: Sign up for a free Azure account if you don't have one.
  2. Visual Studio or Visual Studio Code with .NET Core SDK installed.

Step 1: Create an Azure App Plan

  1. Sign in to the Azure portal (https://portal.azure.com ).
  2. Click on "Create a resource" and search for "App Service Plan"
  3. Fill in the required details, such as the resource group, app service plan name, Region, Pricing Plan (Basic).
  4. Click "Review + Create" and then "Create" to create the Azure App Plan .
Step 2: Create an Web App
  1. Select "Web App" from the list and click "Create."
  2. Fill in the required details, such as the resource group, app name, and runtime stack (.NET Core).
  3. Configure the desired settings, including the region, operating system (Linux), and plan size (pricing tier).

  4. Click "Review + Create" and then "Create" to create the Azure Web App.

Step 3: Create a .NET Core Web API Project

  1. Launch Visual Studio or Visual Studio Code and create a new project.
  2. Select the "ASP.NET  Core Web Application" template and choose "API" as the project type.

  3. Configure the project settings and create the project.

Step 4: Implement the .NET Core Web API

  1. In the newly created .NET Core Web API project, open the WeatherForecastController.cs file, which is an example controller that comes with the template.
  2. Define your API endpoints and logic to handle incoming requests. You can create additional controllers and models as needed for your application.

Step 5: Deploy the .NET Core Web API to Azure App Service

  1. Right-click on the project and select "Publish."
  2. Choose "Azure" as the target and select the Azure App Service (Linus)

  3. Follow the publishing wizard, ensuring you select the appropriate settings and configurations. Select the appropriate subscription and web app. 

  4. Skip last step "API Management", if you don't want to configure API Management.
  5. Click "Publish" to deploy your .NET Core Web API to Azure App Service.

Step 6: Test the Deployed API with a Sample Request

  1. Once the deployment is complete, navigate to your Azure App Service in the Azure portal.
  2. Under the "Settings" section, find the "URL" of your deployed API.
  3. Open a tool like Postman or use a browser to make a sample request to your API. For example:
    GET https://your-app-service-url/api/weatherforecast
    
    This will fetch weather forecast data from your deployed API.

Conclusion:

By following this step-by-step guide, you have successfully created an Azure App Service, deployed a .NET Core Web API, and tested it with a sample request. Azure App Service simplifies the process of hosting and managing web applications, allowing you to focus on building robust and scalable APIs without worrying about infrastructure management. Now you can continue to expand your API and leverage the power of Azure services to enhance your application further. Happy coding!