Step 1: Prepare resources

更新时间:
复制 MD 格式

This topic describes how to prepare the resources for this lab, including creating projects, managing environments, and creating mock APIs.

Create projects and manage environments

Before you use the integration platform, connect to a container cluster, create a project, and create an environment. For details, see Create projects and manage environments.

We recommend the following configurations for this lab:

  • container cluster: An ACK 1.24 or 1.26 cluster in the China (Hangzhou) region.

  • container registry: An ACR Personal Edition registry in the China (Hangzhou) region. The container registry must be in the same region as the container cluster.

Create mock APIs

In this lab, you will orchestrate two APIs. You can use API Gateway to mock the APIs, which simplifies the process. For a quick start guide, see Access backend services over HTTP by using API Gateway. This lab uses only a few features of API Gateway. The steps are as follows:

  1. Activate API Gateway.

    Before you configure the mocks, log on to the API Gateway Console and verify that API Gateway is activated.

  2. Create an API group.

    1. In the left-side navigation pane of the API Gateway Console, choose API Management > Group Management. On the Group Management page, click Create Group in the upper-right corner.

    2. In the Create Group dialog box, select shared instance***, enter a Group Name such as bw-mock, and leave the Basepath at its default value of /. Then, click OK.

  3. Create an API to query train schedules, define its basic information, and publish the API.

    1. On the Group Management page, find the bw-mock API group. In its Actions column, click API Management.

    2. On the API List page for the target group (for example, bw-mock), click Create API in the upper-right corner.

      1. On the Basic Information page of the Create API wizard, the Group parameter defaults to the bw-mock group you created. Set the API Name to mock-traininfo and Security Authentication to No Authentication. Then, click Next.

      2. On the Define API Request page, configure the request details. Set the request path to /traininfo and the HTTP method to GET. In the request parameter section, click Add, set the parameter name to trainno, and select Query for the parameter location. Then, click Next.

      3. On the Define API Backend Service page, configure the mock response.

        For Backend Configuration, select Custom Backend Service. For backend service type, select Mock. In the Mock Return Result field, enter the following code, and set the HTTP Status Code to 200. In the Mock Header section, click Add, set the Header Name to Content-type and the Header Value to application/json. After you complete the configuration, click Next.

        Example mock response:

        {
            "status": "0",
            "msg": "ok",
            "result": {
                "trainno": "G1",
                "list": [
                    {
                        "sequenceno": "1",
                        "station": "Beijing",
                        "day": "1",
                        "arrivaltime": "-",
                        "departuretime": "07:00"
                    },
                    {
                        "sequenceno": "2",
                        "station": "Shanghai",
                        "day": "1",
                        "arrivaltime": "11:29",
                        "departuretime": "-"
                    }
                ]
            }
        }
      4. On the Define Response page, click Create.

      5. In the API Created Successfully dialog box, click Publish.

      6. In the Publish API dialog box, select the Online environment, enter a description in the Change Description text box, and then click Publish.

  4. Verify the API call.

    On the API details page, you can find the public subdomain and Path in the Request Basic Definition section. The public subdomain is the invocation URL that API Gateway automatically generates for your API group. You can use a tool such as Postman to call the API and verify the result.

  5. Repeat Steps 3 and 4 to create a mock API for querying city weather.

    Set the API Name to mock-city-weather, the request path to /weather/city, and the HTTP method to GET. In the request parameter section, add a parameter and set the parameter name to cityname and the parameter location to Query. Example mock response:

    {
        "ret": 200,
        "data": {
            "now": {
                "night_air_temperature": "24",
                "day_air_temperature": "31",
                "wind_direction": "East wind",
                "wind_power": "Level 4-5 turning to Level 3-4",
                "weather": "Cloudy"
            }
        }
    }

    Save the API, publish it to the Online environment, and then use a tool such as Postman to verify the API call.