Application functions
The azion/applications functions that create the client and create, list, read, update, and delete an application, with the methods an application carries.
These azion/applications functions act on the application itself: the factory that builds a client, the functions that create, list, read, and update an application, the delete, and the methods an application object carries for its sub-resources. Every function takes one object argument.
createAzionApplicationClient
Creates a client that holds a token and exposes the six application-level functions as methods. createAzionApplicationClient is also the default export of the module. In TypeScript with moduleResolution set to nodenext, the default import is not callable, so import the named export. With moduleResolution set to bundler, both imports type-check.
| Parameter | Type | Required | Description |
|---|---|---|---|
token |
string |
No | Your Azion personal token. |
options |
AzionClientOptions |
No | Request options. No sample on this page passes them to the client. |
Returns an AzionApplicationsClient. Its methods take the same object as the matching function on this page. The client has no methods for origins, cache settings, device groups, function instances, or rules: call those functions directly, or use the application methods.
This sample creates a client and prints its methods:
Output:
createApplication
Creates an application.
| Parameter | Type | Required | Description |
|---|---|---|---|
data |
ApiBaseApplicationPayload |
Yes | The settings of the application. name is required. |
options |
AzionClientOptions |
No | Request options. |
Returns data as the created AzionApplication, with the id the API assigned. On an error status, the function throws.
The type declares application_acceleration, but API v3 refuses it in a create request as an unknown field. With it, the function throws Error: HTTP error! Status: 400 - BAD REQUEST, so leave it out.
This sample is JavaScript, because TypeScript rejects the string 'http,https' for delivery_protocol, whose type is the DeliveryProtocol enum:
Output:
getApplications
Lists the applications of the account, one page at a time.
| Parameter | Type | Required | Description |
|---|---|---|---|
params |
ApiListApplicationsParams |
No | Pagination: page and page_size. Without ordering keys, the function asks for the list ordered by name, in ascending order. |
options |
AzionClientOptions |
No | Request options. |
Returns an AzionApplicationCollectionResponse: data.results holds the page, and data.count holds the number of applications in the account. On an error status, the function throws.
Output:
getApplication
Returns one application by its ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId |
number |
Yes | The ID of the application. |
options |
AzionClientOptions |
No | Request options. |
Returns data as an AzionApplication that carries the application methods. An ID that matches no application makes the function throw Error: HTTP error! Status: 404 - NOT FOUND.
Output:
patchApplication
Sends the application fields you pass in a PATCH request. Use it to rename an application or to change one setting, such as edge_functions: true, which createFunctionInstance requires.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId |
number |
Yes | The ID of the application to update. |
data |
ApiUpdateApplicationPayload |
Yes | The fields to change. Every field is optional. |
options |
AzionClientOptions |
No | Request options. |
Returns data as the updated AzionApplication. On an error status, the function throws.
Output:
putApplication
Sends the application settings you pass in a PUT request.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId |
number |
Yes | The ID of the application to update. |
data |
ApiUpdateApplicationPayload |
Yes | The settings of the application. |
options |
AzionClientOptions |
No | Request options. |
Returns data as the updated AzionApplication. On an error status, the function throws.
API v3 can refuse a delivery_protocol value that the type allows. For example, the API can answer delivery_protocol: 'https' with "https" is not a valid choice., and the function then throws.
This sample is JavaScript, because TypeScript rejects the string 'http' for delivery_protocol, whose type is the DeliveryProtocol enum:
Output:
deleteApplication
Deletes an application by its ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId |
number |
Yes | The ID of the application to delete. |
options |
AzionClientOptions |
No | Request options. |
Unlike the other application-level functions, deleteApplication returns an envelope and does not throw. A successful delete returns error with the message Expected JSON response, but got: , so the sample confirms the delete with getApplication, which throws a 404 error for an application that no longer exists.
Output:
Application methods
An application that createApplication or getApplication returns carries the sub-resource functions as methods, already bound to its ID. Each method takes the same object as the matching function, without applicationId. The rule methods sit under rules.request and rules.response, which also fix the phase.
| Property | Type | Methods |
|---|---|---|
origins |
OriginOperations |
createOrigin, getOrigins, getOrigin, updateOrigin, deleteOrigin |
cache |
CacheOperations |
createCacheSetting, getCacheSettings, getCacheSetting, updateCacheSetting, deleteCacheSetting |
devices |
DeviceGroupOperations |
createDeviceGroup, getDeviceGroups, getDeviceGroup, updateDeviceGroup, deleteDeviceGroup |
functions |
FunctionOperations |
createFunctionInstance, getFunctionInstances, getFunctionInstance, updateFunctionInstance, deleteFunctionInstance |
rules.request, rules.response |
RuleOperations |
createRule, getRules, getRule, updateRule, deleteRule |
A list method needs an object argument, even an empty one: {}. This sample reads an application and lists each of its sub-resources through the methods:
Output: