What are Azure Function Proxies?
Azure Function Proxy are quite similar to Azure API management but they are not the same ,they allow us to define a single API surface for multiple function apps.
Azure Function Proxy is a unified API layer (façade) on top of Azure functions hosted inside the Application Service container. A proxy exists as a set of additional HTTP endpoints in front of functions based apps. One important note, proxy calls are billed the same way as Azure Functions. Because proxy is essentially another function, that is pre-warmed and always ready to receive requests.
Now any function app can define an endpoint that serves as a Reverse Proxy for another API. The endpoint can be a function app or it can be anything else.
But Why we need proxy Function ?
In a high load enterprise solution we use APi Management but since we are working with very simple projects and for the best practice for medium and low load solution the best choice is to use azure Functions Proxy .
Azure Function Proxies come to the rescue by providing a unified URI (Uniform Resource Identifier) which the client can actually consume. In the meantime, we can abstract all of the different function apps or other APIs and it would also enable us to build our API at a faster rate.
Creating Our proxy
First of all we need to create a new azure function from the portal and after it’s created we need to :
- Navigate to the function app in the portal.
- Click New proxy.
- Provide a Name for your proxy, such as “HiProxy”.
- Set the Route template to /api/Task.
- In Backend URL, enter the URL for the HttpTrigger you created on the backend app.
Click Create. - Copy the Proxy URL, and then use Postman or the HTTP client of your choosing, and send a GET request that URL.
In our case this is what the proxy will look like :
{ "$schema": "http://json.schemastore.org/proxies", "proxies": { "/api/Task": { "matchCondition": { "route": "/api/Task", "methods": [ "POST" ] }, "backendUri": "http://proxyfunction01.azurewebsites.net/api/CreateTodo" }, "Collection redirect": { "matchCondition": { "route": "/api/Task", "methods": [ "GET", "OPTIONS" ] }, "backendUri": "https://to-do-api.azurewebsites.net/api/Task" }, "Item redirect": { "matchCondition": { "route": "/api/Task/{id}", "methods": [ "GET", "OPTIONS", "DELETE", "PUT" ] }, "backendUri": "https://to-do-api.azurewebsites.net/api/Task/{id}" } } }
In order to understand all the steps you can enjoy the below video