A guide on how to build, deploy and operate a Function App in Azure and push the App file to a repository on GitHub.
Published: 2023-07-13 14:22:08

**This blog is expected to serve as a guide to beginners' who may be interested in learning the basics of how to build and operate a serverless applications on an end-to-end platform.**

**Do you wish to deliver more value to the core of your business by minimizing the time and resources you spend on infrastructure-related requirements? This may be a perfect starting point for you to learn how to use fully managed, end-to-end Azure serverless solutions to boost developer productivity, optimize resources, and accelerate the pace of innovation in your organization.**

**We will build and deploy on Azure a function app calculator that uses http trigger to sum-up variables x and y whose values must be integers and returns their sum.**



**Prerequisites**
1. Azure Account.
2. Download and install Visual Studio.
3. GitHub Account.


**Roadmap**
1. Create a Function App using Azure portal.
2. Code and build the function using Visual Studio.
3. Push Function to Azure from Visual Studio.
4. Test the Function App on your browser.
5. Push the function file to GitHub and document with README.

**Here we go!**

**Step 1: Create a Function App using Azure portal**

- Login to **Azure Portal** using the URL `https://portal.azure.com/`

- Type and select **Function App** on the search bar at the top of the page.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cgkafu2ukrd58onwjd3p.png)

- On the **Function app** page, click on **Create**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7qs8t04u3wm0c9wz0vwj.png)

- Under **Basic**, you can see **Project details** enter your **Subscription**, **Resource group** and **Function app name**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bww8tvtgrl9zp7a21yhe.png)

- Moving further down the same page, select **Code** as what you are deploying, chose **.NET** as the **Runtime stack**, select **Version** and **Region**. Under **Operating System**, chose **Windows**. Then click on **Review + create** button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpxgbcreg5q0gvzwugdk.png)

- Summary of your **configuration**, click **Create** button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74s72inzz7sb3sysvfyb.png)

- Deployment is in progress!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/umm420hb3ptcjjbeus3q.png)

- Your deployment is complete! Click on **Go to resource**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wgo8l7zgwebmom3zm0r.png)

- An **Overview** of your **Function app**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jn88h34vfeiqgcrbv9zx.png)


**Step 2: Code and build the function using Visual Studio.**

- Open your **Visual Studio** and click on **Create a new project**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14wm83mzgv5brxdurpdo.png)

- On **Create a new project** page, type Azure in the search bar and select **Azure Functions** from the displayed list.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/155o1mero9cvxj9060t5.png)

- On **Configure your new project** enter **Project name** and the same name will appear in the **Solution name**, select **Location** if you wish of leave it on the default location and click **Next**.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mlp07zxsnmkdvurlfbmf.png)

- On **Additional information**, select **.NET 6.0** under **Functions worker**, **Http trigger ** under **Functions** and **Authorization level** should be **Function**. Then click   **Create** button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0wh0vp187rnb0p8nk22.png)

- The **Code editor**. Here is where we edit the code function template by changing **public static class** and the function name to **Sum**. We leave the **trigger** unchanged since it is already a Http trigger. We also leave the **Log Information** and delete the others, replacing them with this lines of code 

```
int x =int.Parse(req.Query["x"]);

int y =int.Parse(req.Query["y"]);

int result = x + y;

return new OkobjectResult(result);
```
**from line 21 - 25** 
We check our notifications and make sure our code is error-free. Then click on **Build**.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3hb5a5sfa6ol5iullsh.png)

- Building in progress!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fspikoxmbumhrlb3r3h5.png)

- Building Completed and ready for publishing.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7c5p9xebrgesmrnzttk5.png)

**Step 3: Push Function to Azure from Visual Studio.**

- Click on **Build** button at the top of the page and select **Publish section** button on the displayed list.

- Under **Publish** **Target** select **Azure** and click **Next**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9p8t4vq37ddzxm6qqpue.png)


- On **Specific target**, select **Azure Function App (Windows)** and click **Next**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oeocgo70r76n6fkn156t.png)

- On **Select existing or create a new Azure Function**.
Select the **Resource Group** of the Function app you created earlier in Azure portal by clicking on it. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7kqk70j6c87infv951oq.png)

- Then select the Azure function app that you created earlier and click on **Finish** button bellow.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cw9xrrdluwtijee5b3z8.png)

- **Publish profile creation progress** click **Close** when it is done. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pokaym42utrh4kccqge.png)

**Ready to Publish!** Click on **Publish**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9bj1l5frnmad9e36jnz.png)

- **Published Successfully**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iekiagtvjje87zcyb6b7.png)


**Step 4: Test the Function App on your browser.**

- Go back to the **Azure portal** and click on your **Function app** to open the **Overview** page. Copy the URL and paste it into your browser.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b3j9uf5wml5v2midmqy.png)

**Your Function App is running!**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bi1z6acqaxzsmqsajnm.png)

- **To test the Function**, click on the function name **Sum**  under **Functions** on your function app **Overview** page. This will open the **Function** page. Then click on **Get Function Url** and copy the displayed Url.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywtof9vzewhy4rmcvunw.png)

- Paste the copied Url into your browser and provide values for the **Function Variables x and y**. To provide the values, at the end of the Url in the browser, where you have this symbol **==** enter the values in this format **&x=500&y=300** hit **enter**. This will trigger the **Function** to run and return a result which is the sum of the two values we provided, in this instance, **800**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3k4kn9owml7w839e7fad.png)


**Step 5: Push the function file to GitHub and document with README.**

- Go back to the **Visual Studio**, at the bottom extreme left of the **Successfully published** page of the **Function**, click on **Select Repository** this will give you options, select **Git** and the page bellow will be opened **Create a Git repository**. Complete the page accordingly.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wq0vxoufqthtziit0ylz.png)
Decide to either make the repository **Private** or Public by ticking accordingly as shown. Then click **Create and Push** button. This will create a repository of Github and push the Function files to it.

- Go to your Github account and view the **repository**.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8t0nmri87cojqpgogry.png)

**Inside the repo**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wk91fdkimihmcoocz89p.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjlp2a05gtx4volqcmv3.png)

- Click on the **README** file and edit. Remember to format your README for readability, use headers and bullet points, and include any relevant code snippets or screenshots to make it easier for users to follow along and understand your Azure serverless application.

- The **README** documentation of our application.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkosqy5e6fo0f6f7we2w.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nzuvoachxdytv7saetto.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/750pfa21d51qotah9jbz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1psjy4nanxpj92mm5o0f.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0nfzh79h27nor5rkd90d.png)

**Thank you for reading!**