What is Azure Function?
Azure Functions is an event-driven, serverless compute platform used to run snippets of code in Azure. Azure Functions provide flexibility in deploying applications and creating automation. If you are modernizing your application from on-premises server
What is Serverless Computing?
Serverless computing hosts and runs code in the cloud. You do not need to install or maintain servers to run code.
When to use Azure Functions?
- Building Web API: Implement an endpoint for your web applications using the HTTP trigger
- Process File Upload: Run code when a file is uploaded or changed in blob storage
- Respond to database Change: Run custom logic when a document is created or updated in Cosmos DB
- Run Schedule Tasks: Execute code on pre-defined timed intervals
- Create reliable message queue systems: Process message queues using Queue Storage, Service Bus, or Event Hubs
- Analyze IoT data streams: Collect and process data from IoT devices
- Process data in real time: Use Functions and SignalR to respond to data at the moment
Prerequisites
Make sure we have Azure subscription. (We used free trial subscription)
Visual Studio [ Community | Professional | Enterprise] with Azure development
Now lets login into Azure portal, and click on Function app
It will show the below screen, where we don’t have any function app.
Let's create it by clicking on Create option in top menu
Specify Function app name and other configurations as per below screen.
Once you create Function app in azure portal deployment screen will be appearing. Let's wait till finishes the process
We can now add Function trigger, with azure portal
But at moment I will not add functions through azure portal but we will create from Visual Studio and will deploy to azure.
Open Visual Studio and create new Project of Azure Functions Template
Specify Project name
Choose .Net 6.0 as Function Worker
Choose Http trigger
Now you can see Solution explorer and find FunctionApp1 project has been created
Publish Azure Function From Visual Studio:
Right click on Azure FunctionApp Project and click on Publish.
If you have not logged in to Azure account then you need to login, once you logged in then we can now able to see Azure App which we created from Portal.
Click Finish to Complete Publish Profile. And click on Publish option
Once Publishing is Finished then check on Azure Portal
Now, we should have Function1 in Azure portal.
Run /Test Functions:
Click on Function1
Click on Get Function URL option and Copy Function URL
Now let's call this API request from browser
It says that we need to pass query string parameter named as 'name' so let's pass the parameter and its value
Yahoo, we are able to see API Response.