Dynamic API's Addition Script

Dynamic APIs allow you to create and expose new API endpoints through configuration, without plugins or code redeployment. They can invoke existing APIs or trigger workflows with optional request transformations. To expose a dynamic API, the details should be manually added to the avx_dynamic_apis collection in MongoDB, and the config map should be updated. To avoid manual errors, use the patch_dynamic_api.sh script, which automates updates to both the database and configmap. Create or edit dynamic_api.json in appviewx_kubernetes/scripts (refer to dynamic_api.json.template), run the script, and restart the platform gateway pods. Keep dynamic_api.json updated to retain changes after plugin installs or patches.

Steps to Add/Update dynamic APIs:

  1. Ensure that the kube-context is set to the admin user before proceeding. Check the current context using the command below:
    kubectl config current-context
    Expected output:
    kubernetes-admin@kubernetes
    If not set, switch to the admin context (use your admin-context name if different):
  2. Create the JSON file (first-time add). Place the file dynamic_api.json in the scripts folder (appviewx_kubernetes/scripts). Example:
    vi dynamic_api.json
    Note: Add one or more dynamic API objects in valid JSON (see dynamic_api.json.template for reference). Do not remove or modify the dynamic_api.json file unnecessarily to preserve dynamic APIs during plugin installations or apply patches)
  3. Run the patch_dynamic_api.sh script located in appviewx_kubernetes/scripts directory.
    cd <appviewx_installer_path>/scripts
    ./patch_dynamic_api.sh
  4. Once the script is executed,
    • Upserts all records from dynamic_api.json into the avx_dynamic_apis collection (create or update).
    • Adds the API _id values to PUBLIC/apis in avxgw-profile.template inside the platform-gateway Helm chart (for persistence across helm upgrades).
    • Patches the avx-platform-gateway-config config map using avxgw-profile.json.
    • Restarts platform-gateway pods automatically to apply the new config map.
      If the new API IDs already exist in avxgw-profile.template, the script skips the configmap patch and pod restart.
  5. Script logs are written to the appviewx_kubernetes/logs directory.
  6. Edit/append entries in dynamic_api.json and re-run ./patch_dynamic_api.sh. The script will update changed entries and will restart gateway pods only if new API IDs were added to the config map.
  7. During plugin installs or patch operations, the installer checks for dynamic_api.json; if present, it triggers patch_dynamic_api.sh automatically to reapply dynamic APIs to both the database and the platform gateway config map, ensuring that all dynamic APIs remain persistent after any plugin or patch operations.