Read a Function and its Function Instances with the API
Read the code, runtime, and default Args of a Function by its ID with the Azion API v4, and list the Function Instances of an Application.
You can read a Function and its Function Instances in an Application with the Azion API v4.
Prerequisites
- A personal token. To create one, refer to Manage personal tokens.
curl, to call the API, andjq, to format the JSON responses.- The ID of a Function, and the ID of an Application with a Function Instance of that Function. To create the three, refer to Deploy a Function with the Azion API.
Read a Function by its ID
A GET request with the ID of a Function returns its code, its runtime, and its default Args in data.
To read the Function, send a GET request with its ID. Replace the two values with your own:
This excerpt of the response keeps the fields that this section describes:
codeholds the source code of the Function as one JSON string.runtimeis the runtime that executes the code:azion_js.execution_environmentisapplicationfor a Function that runs in an Application, orfirewallfor one that runs in a Firewall.default_argsholds the default Args of the Function. Args are the JSON arguments that a Function Instance passes into the execution of the Function. The API copies the default Args into a Function Instance created withoutargs.reference_countcounts the Function Instances that bind the Function, in all your Applications.
Environment variables are stored on the account, outside the Function, so they are not part of this response. To read them from the code, refer to Environment variables.
To print only the code, as source text instead of a JSON string, replace jq with jq -r .data.code:
You have the runtime, the default Args, and the source code of the Function.
List the Function Instances of an Application
A Function Instance is the entity that binds a Function to an Application or a Firewall. The API lists the Function Instances of an Application under the path of the Application.
To list them, send a GET request with the ID of the Application. The fields parameter limits each result to four fields. Replace the two values with your own:
In each result, function holds the ID of the Function that the Function Instance binds. Both results of this list bind the same Function.
args holds the Args that the Function Instance passes into the execution of the Function. The first Function Instance was created without args, so it holds a copy of the default_args of the Function.
Each Firewall holds its own Function Instances, which bind only Functions whose execution_environment is firewall. To list them, refer to Function instances for Firewall.
For each Function Instance in the list, you have its ID and the ID of the Function it binds.
Read one Function Instance
The path of one Function Instance ends with its own id, not with the ID of the Function. With the ID of the Function in its place, the API answers 404 with code 10004.
To read the Function Instance, send a GET request with its ID and the ID of its Application. Replace the three values with your own:
The response carries the Args of the Function Instance and the ID of the Function it binds.