- Log in to Azure portal and search for Function App. Click to open.
- Click on Create to create a new function app
- Fill in the details in the next tab and click on Review + Create.
- Once it's done deploying, you should click on Go to resource
- Open your Visual studio and click on New to open a new project.
- Select Azure functions and click on continue
- Select Http trigger, you can leave your runtime on .Net6.0, give your function a name and click on continue.
- Your function name automatically comes as your project name in the next tab but you can change it if you want to. You can change the location or leave it on default. If you have version control you can check the version control box and click on create
- Once it opens the code, on line 13 and 15 change the public static class and functionName to Sum because we want to deal with addition as a sample.
- From line 22 to 30, let's take out everything there.
- Copy and paste this code from line 22 int x = int.Parse(req.Query["x"]); int y = int.Parse(req.Query["y"]); int result = x + y;
and on line 26, change the responsemessage to result
- Go to your task bar and click on Build the Build solution
- Once it's done building, it will show you succeeded
- Go to Build again but this time click on Publish to Azure
- Link your Azure account to it and click on Publish
- Go back to Azure and go to your function app overview and click on Refresh
- What we created in visual studio will appear in the functions tab, click it to open.
- Click on Get function URL
- Copy the URL and open a new windows tab to paste it.
- When you paste the URL and add any number to this code in front of the URL to test our Http calculator. &y=10&x=10 this is my own number I am adding
- And there you go. It works!
Top comments (0)