azure-functions

    When enabled, the Plugin terminates the ongoing request to the configured URI and initiates a new request to Azure Functions on behalf of the client with configured authorization details, request headers, body and parameters (all three passed from the original request). It returns back the response with headers, status code and the body to the client that initiated the request with APISIX.

    NameTypeRequiredDefaultDescription
    master_apikeystringFalse“”API Key secret that could be used to access the Azure Functions URI.
    master_clientidstringFalse“”Azure AD client ID that could be used to authorize the function URI.

    Metadata can be used in the azure-functions Plugin for an authorization fallback. If there are no authorization details in the Plugin’s attributes, the master_apikey and master_clientid configured in the metadata is used.

    The relative order priority is as follows:

    1. Plugin looks for x-functions-key or x-functions-clientid key inside the header from the request to APISIX.
    2. If not found, the Plugin checks the configured attributes for authorization details. If present, it adds the respective header to the request sent to the Azure Functions.
    3. If authorization details are not configured in the Plugin’s attributes, APISIX fetches the metadata and uses the master keys.

    You can configure the Plugin on a specific Route as shown below assuming that you already have your Azure Functions up and running:

    1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
    2. {
    3. "plugins": {
    4. "function_uri": "http://test-apisix.azurewebsites.net/api/HttpTrigger",
    5. "authorization": {
    6. "apikey": "<Generated API key to access the Azure-Function>"
    7. }
    8. },
    9. "uri": "/azure"
    10. }'

    Now, any requests (HTTP/1.1, HTTPS, HTTP2) to the endpoint /azure will invoke the configured Azure Functions URI and the response will be proxied back to the client.

    In the example below, the Azure Function takes in name from the query and returns a message “Hello $name”:

    1. curl -i -XGET http://localhost:9080/azure\?name=APISIX
    1. curl -i -XGET --http2 --http2-prior-knowledge http://localhost:9081/azure\?name=APISIX
    1. HTTP/2 200
    2. content-type: text/plain; charset=utf-8
    3. request-context: appId=cid-v1:38aae829-293b-43c2-82c6-fa94aec0a071
    4. server: APISIX/2.10.2
    5. Hello, APISIX

    The azure-functions Plugins also supports URL path forwarding while proxying requests to the Azure Functions upstream. Extensions to the base request path gets appended to the function_uri specified in the Plugin configuration.

    IMPORTANT

    The uri configured on a Route must end with * for this feature to work properly. APISIX Routes are matched strictly and the * implies that any subpath to this URI would be matched to the same Route.

    The example below configures this feature:

    1. curl -i -XGET http://127.0.0.1:9080/azure/HttpTrigger1\?name\=APISIX\
    1. HTTP/1.1 200 OK
    2. Content-Type: text/plain; charset=utf-8
    3. Transfer-Encoding: chunked
    4. Connection: keep-alive
    5. Date: Wed, 01 Dec 2021 14:19:53 GMT
    6. Request-Context: appId=cid-v1:4d4b6221-07f1-4e1a-9ea0-b86a5d533a94
    7. Server: APISIX/2.11.0

    To disable the azure-functions Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.