This topic describes the parameters supported by RestAPI Writer and how to configure it by using the codeless user interface (UI) or code editor.

Background information

RestAPI Writer can send requests to RESTful APIs to write data. RestAPI Writer receives data from a reader, generates JSON-formatted data based on the setting of the column parameter, and then sends requests to RESTful APIs to transfer the data.

Parameters

To implement data integration, you must add a data source and configure it as the source or destination. You must also configure the data that you want to integrate and the data types. During data integration, a reader extracts data from the source, and a writer writes data to the destination.

The following table describes the parameters that you must configure when you use RestAPI Writer to write data to a RestAPI data source.
Note The following parameters are configured when you add data sources and configure Data Integration nodes.
Parameter Description Required Default value
url The URL of the RESTful API. Yes No default value
dataMode The method that is used to transfer JSON-formatted data in RESTful API requests. Valid values:
  • oneData: Transfer one data record in each request.
  • multiData: Transfer multiple data records in each request. The number of requests is determined by the number of tasks generated by the reader.
Yes No default value
column The columns to write the generated JSON-formatted data. The type field specifies the data type of a column. The name field specifies the JSON-formatted path where the column will be stored. You can specify the column parameter in the following format:

"column":[{"type":"long","name":"a.b" // Store data in the a.b path.},{"type":"string","name":"a.c"// Store data in the a.c path.}]

Note For the column parameter, you must specify the type and name fields.
Yes No default value
dataPath The path to store the JSON-formatted data. No No default value
method The request method. Valid values: post and put. Yes No default value
customHeader The header information transferred to the RESTful API. No No default value
authType The authentication method. Valid values:
  • Basic Auth: basic authentication

    If the data source API supports username and password-based authentication, you can select Basic Auth and configure the username and password to be used for authentication. During data integration, the username and password are transferred to the RESTful API URL for authentication. The data source is connected only after the authentication succeeds.

  • Token Auth: token-based authentication

    If the data source API supports token-based authentication, you can select Token Auth and configure a fixed token value to be used for authentication. During data integration, the token is contained in the request header, such as {"Authorization":"Bearer TokenXXXXXX"}, and transferred to the RESTful API URL for authentication. The data source is connected only after the authentication succeeds.

  • Aliyun API Signature: Alibaba Cloud API signature-based authentication

    If the following conditions are met, you can select Aliyun API Signature and configure the AccessKey ID and AccessKey secret to be used for authentication: The data source you want to connect is an Alibaba Cloud service and the API of this service supports AccessKey pair-based authentication.

No No default value
authUsername/authPassword The username and password used for basic authentication. No No default value
authToken The token used for token-based authentication. No No default value
accessKey/accessSecret The AccessKey pair used for Alibaba Cloud API signature-based authentication. No No default value
batchSize The maximum number of data records that can be transferred in each request when the dataMode parameter is set to multiData. Yes 512

Configuration RestAPI Writer by using the codeless UI

  1. Configure a data source.
    Configure a data source for Target. RestAPI data source
    Parameter Description
    Connection Select RestAPI from the left-side drop-down list and a data source from the right-side drop-down list.
    Request Method This parameter corresponds to the method parameter that is described in the Parameters section.
    Data structure of request parameters This parameter corresponds to the dataMode parameter that is described in the Parameters section.
    BatchSize This parameter corresponds to the batchSize parameter that is described in the Parameters section.
    json path to store data This parameter corresponds to the dataPath parameter that is described in the Parameters section.
    Header This parameter corresponds to the customHeader parameter that is described in the Parameters section.

Configuration RestAPI Writer by using the code editor

The following code shows a configuration example:
{
    "type":"job",
    "version":"2.0",
    "steps":[
        {
            "stepType":"stream",
            "parameter":{

            },
            "name":"Reader",
            "category":"reader"
        },
        {
            "stepType":"restapi",
            "parameter":{
                "url":"http://127.0.0.1:5000/writer1",
                "dataMode":"oneData",
                "responseType":"json",
                "column":[
                    {
                        "type":"long", // Store data in the a.b path.
                        "name":"a.b"
                    },
                    {
                        "type":"string", // Store data in the a.c path.
                        "name":"a.c"
                    }
                ],
                "method":"post",
                "defaultHeader":{
                    "X-Custom-Header":"test header"
                },
                "customHeader":{
                    "X-Custom-Header2":"test header2"
                },
                "parameters":"abc=1&def=1",
                "batchSize":256
            },
            "name":"restapiwriter",
            "category":"writer"
        }
    ],
    "setting":{
        "errorLimit":{
            "record":"0" // The number of error records.
        },
        "speed":{
            "throttle":false, // Specifies whether to enable throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The concurrent parameter takes effect only when throttle is set to true.
            "concurrent":1 // The maximum number of concurrent jobs.
        }
    },
    "order":{
        "hops":[
            {
                "from":"Reader",
                "to":"Writer"
            }
        ]
    }
}