CORS – stands for Cross-Origin Resource Sharing. It is used to protect cross-origin request between your server and browser. Azure Functions allows sharing of resources using CORS. You simply have to whitelist the domain which you want your function to accept request from.
In this blog post we will work on series of steps before configure CORS in Azure Functions. Various steps that will be carried out will be as follows.
- Create Azure Function & Test using Postman
- Publish the Web Application using Azure App Service (Web App) & test the Web App
- Configure CORS and re-test the Web Application.
Login to Azure Portal and create a Function App.
Once the Function App is created successfully. Create a + New function. Select the development environment as Azure Portal. Choose the below Template – “Webhook + API”
You will see a pre-defined run.csx code which returns – “Hello, name” based on the name used while doing a POST to the function API.
We will be using this sample code. Save the function. Click on </> Get function URL to get the URL.
Lets quickly test the function using Postman. We pass a json message to the function and it returns output as below.
In our next blog post we will publish this Web Application using Azure App Service (WebApp) and configuring CORS.
Stay tuned for the next blog post !