Help Center> ServiceStage> API Reference> Examples> Application Management

Application Management

Scenario

This section describes how to manage applications by calling APIs. For details about how to call APIs, see Making an API Request.

Process

  1. Create an application.
  2. Add environment variables for the application.
  3. Query the application.

Prerequisites

  • You have called the API to obtain the Identity and Access Management (IAM) token for authentication. You have also set the token to an environment variable. That is, export Token={token}.
  • You have obtained the endpoint of ServiceStage. For details, see Regions and Endpoints. The following uses {servicestage_endpoint} as an example.

Procedure

  1. Create an application. Call the API for creating an application. The following shows an example request.

    curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X POST "https://{servicestage_endpoint}/v2/{project_id}/cas/applications" -d '{
        "name": "TestApp", 
        "description": "application_description", 
        "enterprise_project_id": "0"
    }'

    Information similar to the following is displayed.

    {
        "id": "06cf2fda-af45-44b4-9e22-6294c4804515", 
        "name": "TestApp", 
        "description": "application_description", 
        "creator": "string", 
        "project_id": "bf8523d898b64e4eb956e3be3555ca16", 
        "enterprise_project_id": "0", 
        "create_time": 1578984171041, 
        "update_time": 1578984171041
    }

    id will be replaced with {application_id} in the following example.

  2. Add environment variables for the application. Components deployed in the application can inherit these environment variables. Call the API for modifying application configurations. The following shows an example request.

    curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X PUT  "https://{servicestage_endpoint}/v2/{project_id}/cas/applications/{application_id}/configuration" -d '{
        "environment_id": "0fa75dfe-0d32-4bc1-848b-8008cf3f2567", 
        "configuration": {
            "env": [
                {
                    "name": "app-env", 
                    "value": "env"
                }
            ]
        }
    }'
    Information similar to the following is displayed.
    {
        "application_id": "06cf2fda-af45-44b4-9e22-6294c4804515", 
        "environment_id": "0fa75dfe-0d32-4bc1-848b-8008cf3f2567", 
        "configuration": {
            "env": [
                {
                    "name": "app-env", 
                    "value": "env"
                }
            ]
        }
    }

  3. Query the application based on the application ID. Call the API for obtaining application details based on the application ID. The following shows an example request.

    curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X GET "https://{servicestage_endpoint}/v2/{project_id}/cas/applications/{application_id}"

    Information similar to the following is displayed.

    {
        "id": "06cf2fda-af45-44b4-9e22-6294c4804515", 
        "name": "TestApp", 
        "description": "description", 
        "creator": "xxx", 
        "project_id": "bf8523d898b64e4eb956e3be3555ca16", 
        "enterprise_project_id": "0", 
        "create_time": 1578984171041, 
        "update_time": 1578984171041
    }