Azure Function Proxy
Proxies are simple yet powerful feature of Azure functions. it
provides a way to intercept incoming HTTP traffic to an Azure function and
control its flow based on an application’s need.
Pros - Proxies are helpful in many different ways,
- Call intercept – Enable intercepting incoming HTTP traffic to an azure function.
- Call routing – Route incoming HTTP calls to a different function either within same function app or to a completely different function app.
- Header manipulation – Manipulate HTTP header of an incoming request before routing to a different function. Similarly an azure function’s response can also be manipulated before reverting back to client.
- CORS - Its mandatory to enable CORS for function app to enable communication with sample todo app. Proxy removes this dependency completely as the call always considered to be within same domain.
Demo - Enough
details let’s see it in action. I have created a Todo application with simple CRUD (add, read and delete only) operations. The source is available at
https://github.com/SonuK21/AzFunctionProxy. The repository contains two folder,
https://github.com/SonuK21/AzFunctionProxy. The repository contains two folder,
- TodoApi – An azure function with supported functionality.
- TodoApp – A simple angular app to consume the api.
Publish Todo API – Lets publish the API by following below steps. I am using visual studio 2019.
- Open solution in visual studio and build
- Once the project is build then right click on project file and hit publish,

- Create a new publish profile by providing all the necessary details like
- Name - Any unique name for your function app.
- Subscription - Your azure subscription to be used to publish the app.
- Resource group - A logical container for all resources related to the function app.
- Location - Any closest azure data center's location to host the app.
- Azure storage - A storage that will be used by azure to store your app files.
- Below screens show a step by step guide to create profile.





- Your API is ready to serve, take the highlighted app URL from previous screen. If you try to request API for a list of todos then it should return an empty as there is no record as of now.

Publish Todo Sample App - Lets publish the sample app so that we can integrate the todo API. I had already deployed the sample app in azure storage as I found it quickest way to host a static app on Azure. Please refer https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website for more details on hosting static websites in Azure storage. Once you are done then your sample app should be up and running on a different URL in azure like this,

Proxy - Now, we have two different service running in azure and each can be reached by their respective URLs only. Here comes the use case where proxy can be helpful. Lets try to understand the workflow and see that, how proxies could be helpful,
Thanks for reading.

Proxy - Now, we have two different service running in azure and each can be reached by their respective URLs only. Here comes the use case where proxy can be helpful. Lets try to understand the workflow and see that, how proxies could be helpful,
- Configure proxy in our function app.
- Intercept the incoming traffic targeting function app's root i.e. https://yourfunctionappname.azurewebsites.net/ and route this traffic to our sample app so that a UI can be presented.
- Remove CORS dependency
- User should be able to perform operations like add/read/delete todos directly by hitting the function app's URL
Configuring proxy - One easiest way is to configure proxies from azure portal directly. But if you want to understand each bit of it then proxies.json is the one and lets just try it,
- Add a proxies.json file in your azure function project.

- Right click on file and update property copy to output directory and set to copy if newer.

- We have added two proxies (You can add more depending on requirements),
- proxyHome - It will intercept all incoming calls to function app default URL i.e. https://yourfunctionappname.azurewebsites.net/ and redirect them to todo sample add index page.
- proxyContent - Similarly this will route all incoming calls to other content like CSS, JavaScript etc to /content directory within todo sample app.

- Few points to notice,
- methods - An array of allowed HTTP verbs/methods supported by this proxy
- route - The URL route against which this proxy needs to be triggered. i.e. any incoming call to aforesaid URL will automatically be served by respective proxy.
- backendUrl - Any endpoint(Our sample app URL in this case) which will actually serve these requests.
- Its done. If you try to hit function app's URL now then it should open the sample todo app instead just like the screen below,
- Notice the URL, its function app (API) not the sample todo page.
Thanks for reading.












