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.
Name | Type | Required | Default | Description |
---|---|---|---|---|
master_apikey | string | False | “” | API Key secret that could be used to access the Azure Functions URI. |
master_clientid | string | False | “” | 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:
- Plugin looks for
x-functions-key
orx-functions-clientid
key inside the header from the request to APISIX. - 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.
- 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:
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"function_uri": "http://test-apisix.azurewebsites.net/api/HttpTrigger",
"authorization": {
"apikey": "<Generated API key to access the Azure-Function>"
}
},
"uri": "/azure"
}'
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”:
curl -i -XGET http://localhost:9080/azure\?name=APISIX
curl -i -XGET --http2 --http2-prior-knowledge http://localhost:9081/azure\?name=APISIX
HTTP/2 200
content-type: text/plain; charset=utf-8
request-context: appId=cid-v1:38aae829-293b-43c2-82c6-fa94aec0a071
server: APISIX/2.10.2
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:
curl -i -XGET http://127.0.0.1:9080/azure/HttpTrigger1\?name\=APISIX\
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Wed, 01 Dec 2021 14:19:53 GMT
Request-Context: appId=cid-v1:4d4b6221-07f1-4e1a-9ea0-b86a5d533a94
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.