HTTP integration

更新时间:
复制 MD 格式

The Moflow platform provides a powerful HTTP integration feature that lets you seamlessly connect to and interact with HTTP services through simple configuration. This document describes how to create and use an HTTP integration.

Feature introduction

The HTTP integration feature of the Moflow platform supports the following capabilities:

  • Stream support: You can enable Server-Sent Events (SSE) in the configuration panel to support data streaming.

  • Custom trigger methods: You can set integration operations to trigger manually or run automatically to meet the requirements of different business scenarios.

  • Callbacks and data transformation: You can execute specific integration operation events when a query succeeds or fails and perform custom processing on the returned data.

  • Advanced settings: You can use advanced configurations for debouncing and execution prevention conditions to optimize the execution of integration operations.

For more information about events, see Integration operation events.

Use an HTTP integration

Step 1: Create an HTTP integration

  1. Log on to the Moflow platform and go to the console.

  2. Navigate to Resources > Integrations and click Create Integration.

  3. Select HTTP Configuration and enter a name and description for the integration.

  4. Configure HTTP integration information for different environments, including Authentication Settings and Base URL.

  5. Click OK to create the HTTP integration.

Step 2: Create an integration operation within an application

  1. In the Code panel, click the plus sign (+) for the corresponding scope, and select Integration Operation.

  2. Select the HTTP integration that you created as the resource, select a method, and enter a path. Then, you can select a trigger method and configure more detailed settings for the integration operation as needed.

  1. Click Run to preview the query result.

Configuration panel details

Integration configuration

  • Base URL: Defines the base URI for the HTTP request.

  • URL Parameters: Defines the query parameters for the HTTP request.

  • Header Parameters: Defines the header parameters for the HTTP request.

  • Authentication Settings: Defines the authentication protocol for the HTTP request. The options include No Authentication, Bearer Token, Alibaba Cloud OpenAPI, EPaaS Protocol, and Custom Protocol.

    Note

    The Alibaba Cloud OpenAPI protocol supports the configuration of request parameters. It automatically calculates the signature and generates a request message that complies with the Alibaba Cloud OpenAPI protocol. For more information about how to configure Alibaba Cloud OpenAPI protocol request message parameters, see V3 request body & signing mechanism.

    Custom Protocol: The custom protocol lets you customize the processing of parameters for an HTTP request. In a custom script, you can use JavaScript to further process parameters from the integration configuration and integration operation. In the custom key list, you can add the keys that you need and retrieve them in the custom script using data.keys.In the custom script, you can retrieve the parameters of the HTTP request through the object attributes of data. Use data.url, data.parameters, data.headers, and data.body to retrieve the URI of the request, query parameters, header parameters, and request body, respectively. After you process the parameters in the custom script, you must return an object that contains the parameters, headers, and body. The HTTP integration then replaces the original query parameters, header parameters, and request body in the HTTP request with the object that you return. The following example shows how to sign the HTTP request method, current time, and request body using the custom key secretKey, and then add the signature result and the custom key apiKey to the header before returning the object.

    // Utility packages
    const DateFns = require("date-fns");
    const DateFnsTz = require("date-fns-tz");
    const CryptoJS = require("crypto-js");
    
    const { format } = DateFns;
    const { toZonedTime } = DateFnsTz;
    
    
    // Get the current time
    const now = new Date();
    const timeZone = 'Asia/Shanghai';
    
    // Convert the current time to the time in the specified time zone
    const zonedDate = toZonedTime(now, timeZone);
    const formattedDateTime = format(zonedDate, "yyyy-MM-dd'T'HH:mm:ss.SSS");
    
    // Get HTTP request parameters and the keys from the integration configuration in data
    const url = data.url;
    const method = data.method;
    const parameters = data.parameters;
    const headers = data.headers;
    const body = data.body;
    const keys = data.keys;
    
    // Construct the string to be signed
    const stringToSign = method + '\n' + formattedDateTime + '\n' + body;
    
    // Use the utility package to sign the string
    const signature = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(stringToSign, data.keys['secretKey']));
    
    // Construct the new header
    let newHeaders = {
        ...headers, // Return other header information
        'apiKey': keys['apiKey'],
        'Signature': signature,
    };
    // The returned result includes query parameters, headers, and the request body
    return {
        parameters: parameters,
        headers: newHeaders,
        body: body
    };
    Note

    In the custom script of a custom protocol, you can import the signing function utility package using require("crypto-js"). For more information about how to use the crypto-js utility package, see crypto-js. You can import the time function utility packages using require("date-fns") and require("date-fns-tz"). For more information about how to use the date-fns utility package, see date-fns. For more information about how to use the date-fns-tz utility package, see date-fns-tz.

    Important

    Custom protocols require Alibaba Cloud Function Compute. Ensure that you have enabled Alibaba Cloud Function Compute. For more information about Alibaba Cloud Function Compute (FC) and how to enable it, see Function Compute (FC).

General configurations

  • Parameters: Defines the parameters required for the query, including the type, default value, and description. In a search statement, you can reference parameters using {{ varName }}.

  • sse: Defines whether to use data streaming for each round of dialogue.

  • method: Defines the method and URI for the HTTP service call.

    Note

    The complete URI of the request is a concatenation of the Base URL parameter from the integration configuration and the url configured in the method parameter of the integration operation.

  • query: Defines the query parameters for the HTTP request.

  • Header: Defines the header parameters for the HTTP request.

  • cookies: Defines the cookie parameters for the HTTP request.

  • contentType: Defines the content-type for the HTTP request data.

  • data: Defines the data for the HTTP request.

  • Disable URL encoding: If you enable this switch, the query parameters in the query are not URL-encoded. If your query parameters are already URL-encoded and you do not want them to be encoded again, enable this switch.

  • Timeout: Configures the maximum running time for the operation.

  • Description: Provides a detailed description of the integration operation.

Callback configuration

  • Data transformation: Processes the data that is returned by the API. The default value is return data, which means that no processing is performed.

  • Stream reception callback: Configures the event to trigger when chunk data is retrieved from a streaming API call.

  • Success callback: Configures the event to trigger when the API call is successful.

  • Failure callback: Configures the event to trigger when the API call fails.

Advanced configuration

  • Debounce: Sets a debounce expression to prevent frequent API calls.

  • Execution prevention condition: Determines whether to execute this integration operation based on a conditional expression.

Manually trigger an integration

Event trigger

  1. In the component where you want to trigger the integration operation, configure an event handler.

  2. Set the action type to Integration Operation and select the corresponding integration.

  3. Enter the configured parameters as an object.

API trigger

If the name of the integration operation is action1, you can trigger the integration operation using the action1.trigger() method anywhere a script can be executed. If the integration operation has configured parameters, you must enter them as an object.