Azion Application module

The Azion Application module provides a comprehensive interface to interact with the Azion Edge Application API. This module allows you to manage edge applications and their components including cache settings, device groups, function instances, origins, and Rules Engine configurations.

Go to Azion Libraries Overview

You can interact with the API using a client or calling the methods directly from the library. When making direct calls, you can use the environment variables to configure the client without passing the token and debug parameters directly.

This is an example of how a .env file with your environment variables may look like:

Terminal window
AZION_TOKEN=your-api-token
AZION_DEBUG=true
VariableDescription
AZION_TOKENYour Azion API token.
AZION_DEBUGEnable debug mode (true/false).

Usage


createClient

TypeScript example:

import createClient from '@azion/applications';
const client = createClient({
token: 'your-api-token',
options: { debug: true }
});

Usage with Edge Application

createApplication

Creates a new edge application.

TypeScript example:

import { createApplication } from '@azion/applications';
// Create a new application
const { data: newApp, error } = await createApplication({
data: {
name: "My Edge Application",
delivery_protocol: "http,https",
application_acceleration: true
}
});

Parameters:

ParameterTypeDescription
data{ name: string; delivery_protocol: string; application_acceleration: boolean; }The data for the new application.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionApplication>>The created application object or error if creation failed.

getApplications

Lists all edge applications.

TypeScript example:

import { getApplications } from '@azion/applications';
// List all applications
const { data: apps, error } = await getApplications({
params: { page: 1, page_size: 20 }
});

Parameters:

ParameterTypeDescription
params?{ page?: number; page_size?: number; order?: 'id'} | 'name'; sort?: 'asc' | 'desc'; }Optional parameters for filtering and pagination.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationCollectionResponse<AzionApplication>>A collection of applications or error if retrieval failed.

getApplication

Retrieves a specific edge application.

TypeScript example:

import { getApplication } from '@azion/applications';
// Retrieve a specific application
const applicationId = 12345; // Replace with the actual application ID
const { data: app, error } = await getApplication(applicationId, { debug: true });
if (error) {
console.error("Error retrieving application:", error);
} else {
console.log("Application details:", app);
}

Parameters:

ParameterTypeDescription
applicationIdNumberThe ID of the application to retrieve.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionApplication>>The retrieved application object or error if not found.

updateApplication

Updates an existing edge application.

TypeScript example:

import { updateApplication } from '@azion/applications';
// Update an existing application
const applicationId = 12345; // Replace with the actual application ID
const updateData = {
name: "Updated Edge Application",
delivery_protocol: "https",
application_acceleration: false
};
const { data: updatedApp, error } = await updateApplication(applicationId, updateData, { debug: true });
if (error) {
console.error("Error updating application:", error);
} else {
console.log("Updated application details:", updatedApp);
}

Parameters:

ParameterTypeDescription
applicationIdNumberThe ID of the application to update.
data{ name?: string; delivery_protocol?: string; application_acceleration?: boolean; }The updated data for the application.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionApplication>>The updated application object or error if the update failed.

deleteApplication

Deletes an edge application.

TypeScript example:

import { deleteApplication } from '@azion/applications';
// Delete an existing application
const applicationId = 12345; // Replace with the actual application ID
const { data: deletedApp, error } = await deleteApplication(applicationId, { debug: true });
if (error) {
console.error("Error deleting application:", error);
} else {
console.log("Application deleted successfully:", deletedApp);
}

Parameters:

ParameterTypeDescription
applicationIdNumberThe ID of the application to delete.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeletedApplication>>Confirmation of deletion or error if the operation failed.

Cache Settings

createCacheSetting

Creates a new cache setting.

TypeScript example:

import { createCacheSetting } from '@azion/applications';
// Create a new cache setting
const cacheSettingData = {
name: "My Cache Setting",
browser_cache_settings: "private",
cdn_cache_settings: "public"
};
const { data: newCacheSetting, error } = await createCacheSetting(cacheSettingData, { debug: true });
if (error) {
console.error("Error creating cache setting:", error);
} else {
console.log("Cache setting created successfully:", newCacheSetting);
}

Parameters:

ParameterTypeDescription
data{ name: string; browser_cache_settings: string; cdn_cache_settings: string; }The data for the new cache setting.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionCacheSetting>>The created cache setting object or error if creation failed.

getCacheSetting

Retrieve a specific cache setting.

TypeScript example:

import { getCacheSetting } from '@azion/applications';
// Retrieve a specific cache setting
const cacheSettingId = 12345; // Replace with the actual cache setting ID
const { data: cacheSetting, error } = await getCacheSetting(cacheSettingId, { debug: true });
if (error) {
console.error("Error retrieving cache setting:", error);
} else {
console.log("Cache setting details:", cacheSetting);
}

Parameters:

ParameterTypeDescription
cacheSettingIdNumberThe ID of the cache setting to retrieve.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionCacheSetting>>The retrieved cache setting object or error if not found.

getCacheSettings

Lists all cache settings.

TypeScript example:

import { getCacheSettings } from '@azion/applications';
// List all cache settings with optional pagination and sorting
const { data: cacheSettings, error } = await getCacheSettings({
params: { page: 1, page_size: 20, order: 'name', sort: 'asc' },
debug: true
});
if (error) {
console.error("Error retrieving cache settings:", error);
} else {
console.log("Cache settings list:", cacheSettings);
}

Parameters:

ParameterTypeDescription
params?{ page?: number; page_size?: number; order?: 'id' | 'name'; sort?: 'asc' | 'desc'; }Optional parameters for filtering and pagination.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationCollectionResponse<AzionCacheSetting>>A collection of cache settings or error if retrieval failed.

updateCacheSetting

Updates an existing cache setting.

TypeScript example:

import { updateCacheSetting } from '@azion/applications';
// Update an existing cache setting
const cacheSettingId = 12345; // Replace with the actual cache setting ID
const updateData = {
name: "Updated Cache Setting",
browser_cache_settings: "no-cache",
cdn_cache_settings: "private"
};
const { data: updatedCacheSetting, error } = await updateCacheSetting(cacheSettingId, updateData, { debug: true });
if (error) {
console.error("Error updating cache setting:", error);
} else {
console.log("Updated cache setting details:", updatedCacheSetting);
}

Parameters:

ParameterTypeDescription
cacheSettingIdNumberThe ID of the cache setting to update.
data{ name?: string; browser_cache_settings?: string; cdn_cache_settings?: string; }The updated data for the cache setting.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionCacheSetting>>The updated cache setting object or error if the update failed.

deleteCacheSetting

Deletes a cache setting.

TypeScript example:

import { deleteCacheSetting } from '@azion/applications';
// Delete an existing cache setting
const cacheSettingId = 12345; // Replace with the actual cache setting ID
const { data: deletedCacheSetting, error } = await deleteCacheSetting(cacheSettingId, { debug: true });
if (error) {
console.error("Error deleting cache setting:", error);
} else {
console.log("Cache setting deleted successfully:", deletedCacheSetting);
}

Parameters:

ParameterTypeDescription
cacheSettingIdNumberThe ID of the cache setting to delete.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeletedCacheSetting>>Confirmation of deletion or error if the operation failed.

Device Groups

createDeviceGroup

Creates a new device group.

TypeScript example:

import { createDeviceGroup } from '@azion/applications';
// Create a new device group
const deviceGroupData = {
name: "Mobile Devices",
user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
};
const { data: newDeviceGroup, error } = await createDeviceGroup(deviceGroupData, { debug: true });
if (error) {
console.error("Error creating device group:", error);
} else {
console.log("Device group created successfully:", newDeviceGroup);
}

Parameters:

ParameterTypeDescription
data{ name: string; user_agent: string; }The data for the new device group.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeviceGroup>>The created device group object or error if creation failed.

getDeviceGroup

Retrieves a specific device group.

TypeScript example:

import { getDeviceGroup } from '@azion/applications';
// Retrieve a specific device group
const deviceGroupId = 12345; // Replace with the actual device group ID
const { data: deviceGroup, error } = await getDeviceGroup(deviceGroupId, { debug: true });
if (error) {
console.error("Error retrieving device group:", error);
} else {
console.log("Device group details:", deviceGroup);
}

Parameters:

ParameterTypeDescription
deviceGroupIdNumberThe ID of the device group to retrieve.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeviceGroup>>The retrieved device group object or error if not found.

getDeviceGroups

Lists all device groups.

TypeScript example:

import { getDeviceGroups } from '@azion/applications';
// List all device groups with optional pagination and sorting
const { data: deviceGroups, error } = await getDeviceGroups({
params: { page: 1, page_size: 20, order: 'name', sort: 'asc' },
debug: true
});
if (error) {
console.error("Error retrieving device groups:", error);
} else {
console.log("Device groups list:", deviceGroups);
}

Parameters:

ParameterTypeDescription
params?{ page?: number; page_size?: number; order?: 'id' | 'name'; sort?: 'asc' | 'desc'; }Optional parameters for filtering and pagination.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationCollectionResponse<AzionDeviceGroup>>The retrieved device group object or error if not found.

updateDeviceGroup

Updates an existing device group.

TypeScript example:

import { updateDeviceGroup } from '@azion/applications';
// Update an existing device group
const deviceGroupId = 12345; // Replace with the actual device group ID
const updatedName = "Updated Device Group Name"; // Using a variable for the name
const updateData = {
name: updatedName
};
const { data: updatedDeviceGroup, error } = await updateDeviceGroup(deviceGroupId, updateData, { debug: true });
if (error) {
console.error("Error updating device group:", error);
} else {
console.log("Updated device group details:", updatedDeviceGroup);
}

Parameters:

ParameterTypeDescription
deviceGroupIdNumberThe ID of the device group to update.
data{ name?: string; user_agent?: string; }The updated data for the device group.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeviceGroup>>The updated device group object or error if the update failed.

deleteDeviceGroup

Deletes a device group.

TypeScript example:

import { deleteDeviceGroup } from '@azion/applications';
// Delete a specific device group
const deviceGroupId = 12345; // Replace with the actual device group ID
const { data: deletedDeviceGroup, error } = await deleteDeviceGroup(deviceGroupId, { debug: true });
if (error) {
console.error("Error deleting device group:", error);
} else {
console.log("Device group deleted successfully:", deletedDeviceGroup);
}

Parameters:

ParameterTypeDescription
deviceGroupIdNumberThe ID of the device group to delete.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeletedDeviceGroup>>Confirmation of deletion or error if the operation failed.

Function Instances

createFunctionInstance

Creates a new function instance.

TypeScript example:

import { createFunctionInstance } from '@azion/applications';
// Define the data for the new function instance
const functionInstanceData = {
name: "MyFunctionInstance",
entry_point: "index.handler", // Replace with the entry point of your function
timeout: 30 // Adjust the timeout as needed
};
// Create a new function instance
const { data: newFunctionInstance, error } = await createFunctionInstance(functionInstanceData, { debug: true });
if (error) {
console.error("Error creating function instance:", error);
} else {
console.log("Function instance created successfully:", newFunctionInstance);
}

Parameters:

ParameterTypeDescription
dataApiCreateFunctionInstancePayloadThe data for the new function instance.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionFunctionInstance>>The created function instance object or error if creation failed.

getFunctionInstance

Retrieves a specific function instance.

TypeScript example:

import { getFunctionInstance } from '@azion/applications';
// Retrieve a specific function instance
const functionInstanceId = 12345; // Replace with the actual function instance ID
const { data: functionInstance, error } = await getFunctionInstance(functionInstanceId, { debug: true });
if (error) {
console.error("Error retrieving function instance:", error);
} else {
console.log("Function instance details:", functionInstance);
}

Parameters:

ParameterTypeDescription
functionInstanceIdNumberThe ID of the function instance to retrieve.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionFunctionInstance>>The retrieved function instance object or error if not found.

getFunctionInstances

Lists all function instances.

TypeScript example:

import { getFunctionInstances } from '@azion/applications';
// List all function instances with optional parameters for pagination
const params = {
page: 1, // Page number for pagination
page_size: 20, // Number of items per page
order: 'name', // Order by name
sort: 'asc' // Sort in ascending order
};
const { data: functionInstances, error } = await getFunctionInstances(params, { debug: true });
if (error) {
console.error("Error retrieving function instances:", error);
} else {
console.log("List of function instances:", functionInstances);
}

Parameters:

ParameterTypeDescription
params?ApiListFunctionInstancesParamsOptional parameters for filtering and pagination.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationCollectionResponse<AzionFunctionInstance>>A collection of function instances or error if retrieval failed.

updateFunctionInstance

Updates an existing function instance.

TypeScript example:

import { updateFunctionInstance } from '@azion/applications';
// Define the ID of the function instance and the updated data
const functionInstanceId = 12345; // Replace with the actual function instance ID
const updatedData = {
name: "Updated Function Instance Name", // New name for the function instance
entry_point: "newIndex.handler", // Updated entry point (example)
};
// Update the function instance
const { data: updatedFunctionInstance, error } = await updateFunctionInstance(functionInstanceId, updatedData, { debug: true });
if (error) {
console.error("Error updating function instance:", error);
} else {
console.log("Updated function instance details:", updatedFunctionInstance);
}

Parameters:

ParameterTypeDescription
functionInstanceIdNumberThe ID of the function instance to update.
dataApiUpdateFunctionInstancePayloadThe updated data for the function instance.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionFunctionInstance>>The updated function instance object or error if the update failed.

deleteFunctionInstance

Deletes a function instance.

TypeScript example:

import { deleteFunctionInstance } from '@azion/applications';
// Define the ID of the function instance to delete
const functionInstanceId = 12345; // Replace with the actual function instance ID
// Delete the function instance
const { data: deletedFunctionInstance, error } = await deleteFunctionInstance(functionInstanceId, { debug: true });
if (error) {
console.error("Error deleting function instance:", error);
} else {
console.log("Function instance deleted successfully:", deletedFunctionInstance);
}

Parameters:

ParameterTypeDescription
functionInstanceIdNumberThe ID of the function instance to delete.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeletedFunctionInstance>>Confirmation of deletion or error if the operation failed.

Origins

createOrigin

Creates a new origin.

TypeScript example:

import { createOrigin } from '@azion/applications';
// Define the data for the new origin
const newOriginData = {
name: "My New Origin", // Name of the origin
url: "https://example.com" // URL of the origin
};
// Create a new origin
const { data: newOrigin, error } = await createOrigin(newOriginData, { debug: true });
if (error) {
console.error("Error creating origin:", error);
} else {
console.log("Created origin:", newOrigin);
}

Parameters:

ParameterTypeDescription
data{ name: string; url: string; }The data for the new origin.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionOrigin>>The created origin object or error if creation failed.

getOrigin

Retrieves a specific origin.

TypeScript example:

import { getOrigin } from '@azion/applications';
// Define the ID of the origin to retrieve
const originId = 12345; // Replace with the actual origin ID
// Retrieve the specific origin
const { data: origin, error } = await getOrigin(originId, { debug: true });
if (error) {
console.error("Error retrieving origin:", error);
} else {
console.log("Retrieved origin:", origin);
}

Parameters:

ParameterTypeDescription
originIdNumberThe ID of the origin to retrieve.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionOrigin>>The retrieved origin object or error if not found.

getOrigins

Lists all origins.

TypeScript example:

import { getOrigins } from '@azion/applications';
// Define the optional parameters for filtering and pagination
const params = {
page: 1, // Page number
page_size: 20, // Number of items per page
order: 'name', // Sort order by name or id
sort: 'asc' // Sorting direction (ascending)
};
// Retrieve all origins with optional pagination and sorting
const { data: origins, error } = await getOrigins(params, { debug: true });
if (error) {
console.error("Error retrieving origins:", error);
} else {
console.log("List of origins:", origins);
}

Parameters:

ParameterTypeDescription
params?{ page?: number; page_size?: number; order?: 'id' | 'name'; sort?: 'asc' | 'desc'; }Optional parameters for filtering and pagination.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationCollectionResponse<AzionOrigin>>A collection of origins or error if retrieval failed.

updateOrigin

Updates an existing origin.

TypeScript example:

import { updateOrigin } from '@azion/applications';
// Define the origin ID and updated data
const originId = 12345; // Replace with the actual origin ID
const updatedData = {
name: "Updated Origin Name", // New name for the origin
url: "https://new-url.com" // New URL for the origin
};
// Update the origin with the specified ID
const { data: updatedOrigin, error } = await updateOrigin(originId, updatedData, { debug: true });
if (error) {
console.error("Error updating origin:", error);
} else {
console.log("Updated origin:", updatedOrigin);
}

Parameters:

ParameterTypeDescription
originIdNumberThe ID of the origin to update.
data{ name?: string; url?: string; }The updated data for the origin.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionOrigin>>The updated origin object or error if the update failed.

deleteOrigin

Deletes an origin.

TypeScript example:

import { deleteOrigin } from '@azion/applications';
// Define the origin ID to delete
const originId = 12345; // Replace with the actual origin ID
// Delete the origin with the specified ID
const { data: deletedOrigin, error } = await deleteOrigin(originId, { debug: true });
if (error) {
console.error("Error deleting origin:", error);
} else {
console.log("Deleted origin:", deletedOrigin);
}

Parameters:

ParameterTypeDescription
originIdNumberThe ID of the origin to delete.
options?{ debug?: boolean }Optional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeletedOrigin>>Confirmation of deletion or error if the operation failed.

Rules Engine

createRule

Creates a new rule.

TypeScript example:

import { createRule } from '@azion/applications';
// Define the data for the new rule
const ruleData = {
name: "Example Rule",
conditions: {
path: "/example-path"
},
actions: {
redirect: {
url: "https://example.com"
}
}
};
// Create a new rule
const { data: newRule, error } = await createRule(ruleData, { debug: true });
if (error) {
console.error("Error creating rule:", error);
} else {
console.log("Created rule:", newRule);
}

Parameters:

ParameterTypeDescription
data{ApiCreateRulePayloadThe data for the new rule.
options?AzionClientOptionsOptional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionRule>>The created rule object or error if creation failed.

getRule

Retrieves a specific rule.

TypeScript example:

import { getRule } from '@azion/applications';
// Define the rule ID to retrieve
const ruleId = 123;
// Retrieve the specific rule
const { data: rule, error } = await getRule(ruleId, { debug: true });
if (error) {
console.error("Error retrieving rule:", error);
} else {
console.log("Retrieved rule:", rule);
}

Parameters:

ParameterTypeDescription
ruleIdNumberThe ID of the rule to retrieve.
options?AzionClientOptionsOptional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionRule>>The retrieved rule object or error if not found.

getRules

Lists all rules.

TypeScript example:

import { getRules } from '@azion/applications';
// Optional parameters for filtering and pagination
const params = {
page: 1,
page_size: 10,
order: 'id',
sort: 'asc',
};
// Fetch the collection of rules with optional parameters
const { data: rules, error } = await getRules(params, { debug: true });
if (error) {
console.error("Error retrieving rules:", error);
} else {
console.log("Retrieved rules:", rules);
}

Parameters:

ParameterTypeDescription
params?ApiListRulesParamsOptional parameters for filtering and pagination.
options?AzionClientOptionsOptional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationCollectionResponse<AzionRule>>A collection of rules or error if retrieval failed.

updateRule

Updates an existing rule.

TypeScript example:

import { updateRule } from '@azion/applications';
// The ID of the rule to update
const ruleId = 123;
// The updated data for the rule
const data = {
name: "Updated Rule Name",
condition: "new_condition_expression",
action: "new_action_to_perform",
};
// Optional parameters including debug mode
const options = { debug: true };
// Update the rule with the specified ID and data
const { data: updatedRule, error } = await updateRule(ruleId, data, options);
if (error) {
console.error("Error updating the rule:", error);
} else {
console.log("Updated rule:", updatedRule);
}

Parameters:

ParameterTypeDescription
ruleIdNumberThe ID of the rule to update.
dataApiUpdateRulePayloadThe updated data for the rule.
options?AzionClientOptionsOptional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionRule>>The updated rule object or error if the update failed.

deleteRule

Deletes a rule.

TypeScript example:

import { deleteRule } from '@azion/applications';
// The ID of the rule to delete
const ruleId = 123;
// Optional parameters including debug mode
const options = { debug: true };
// Delete the rule with the specified ID
const { data: deletionConfirmation, error } = await deleteRule(ruleId, options);
if (error) {
console.error("Error deleting the rule:", error);
} else {
console.log("Rule deleted successfully:", deletionConfirmation);
}

Parameters:

ParameterTypeDescription
ruleIdNumberThe ID of the rule to delete.
options?AzionClientOptionsOptional parameters including debug mode.

Returns:

Return TypeDescription
Promise<AzionApplicationResponse<AzionDeletedRule>>Confirmation of deletion or error if the operation failed.


Contributors