Azure Functions Proxies

Azure Functions Proxies provide a way to create a single HTTP endpoint that aggregates multiple backend HTTP APIs or other Azure Functions. This is useful for scenarios where you want to expose a unified API surface, abstract underlying implementation details, or combine responses from different services.

What are Function Proxies?

A proxy is a configuration in your Azure Functions app that defines an incoming HTTP request route and maps it to one or more actions. These actions can include:

Key Concepts

Defining Proxies

Proxies are defined in a file named proxies.json in the root of your Azure Functions project.

Example proxies.json

{
    "$schema": "http://json.schemastore.org/proxies",
    "proxies": {
        "myApiProxy": {
            "matchCondition": {
                "methods": [ "GET" ],
                "route": "/api/products/{id}"
            },
            "backendUri": "https://myservice.azurewebsites.net/api/items/{id}",
            "requestOverrides": {
                "header": {
                    "X-Original-Request-ID": "{headers.x-request-id}"
                }
            },
            "responseOverrides": {
                "statusCode": 200,
                "body": "{\"message\": \"Success for product {id}\"}"
            }
        },
        "staticResponseProxy": {
            "matchCondition": {
                "route": "/info"
            },
            "backendUri": "invalid",
            "responseOverrides": {
                "body": "This is static information.",
                "contentType": "text/plain",
                "headers": {
                    "X-Custom-Header": "StaticValue"
                }
            }
        }
    }
}

Understanding the Configuration

myApiProxy Example Breakdown:

staticResponseProxy Example Breakdown:

Route Parameters and Transformations

You can reference route parameters from the matchCondition.route in both backendUri and responseOverrides using the format {parameterName}.

You can also perform more advanced transformations using Liquid templating. For instance, to access request headers, you can use {headers.headerName}.

Note: When using backendUri, if it's not explicitly set, the proxy will try to forward the request to a Function within the same Functions app.

Common Use Cases

Tip: Proxies are great for integrating with existing REST APIs or for creating a facade over your serverless backend.

Limitations

While powerful, proxies have some limitations:

Important: Ensure your proxies.json file is in the root of your Azure Functions project and is deployed correctly with your app.

For more detailed information and advanced scenarios, refer to the official Azure Functions Proxies documentation.