DataWorks allows you to create an API by configuring parameters in the codeless user interface (UI) without the need to write code. This topic describes how to create an API by using the codeless UI.

Prerequisites

A data source is configured on the Data Source page. For more information, see Configure a connection.

Create an API

  1. Go to the DataService Studio page.
    1. Log on to the DataWorks console.
    2. In the left-side navigation pane, click Workspaces.
    3. In the top navigation bar, select the region where the workspace that you want to manage resides. Find the workspace and click DataService Studio in the Actions column.
  2. On the Service Development page, move the pointer over the Create icon and choose API > Generate API.
    Alternatively, expand the desired business process, right-click API, and then choose New > Generate API.
  3. In the Generate API dialog box, configure the parameters.
    Generate API
    Parameter Description
    API mode The mode in which you want to create the API. Valid values: Wizard Mode and Script Mode. In this example, select Wizard Mode.
    API Name The name of the API. The name must be 4 to 50 characters in length, and can contain letters, digits, and underscores (_). The name must start with a letter.
    API Path The storage path of the API. The path is the API request path that corresponds to the service host address, such as /user.
    Note The path can be up to 200 characters in length and can contain letters, digits, underscores (_), and hyphens (-). The path must start with a forward slash (/).
    Protocol Valid values: HTTP and HTTPS.

    If you want to call the API by using HTTPS, you must bind an independent domain name to the API in the API Gateway console after the API is published to API Gateway. You must also upload a Secure Sockets Layer (SSL) certificate in the API Gateway console. For more information, see Enable HTTPS for an API.

    Request Method Valid values: GET and POST.
    Response Content Type The format in which you want the API to return data. Set the value to JSON.
    Visible Range The range of users to which the API is visible. Valid values:
    • Work Space: The API is visible to all members in the current workspace.
    • Private: The API is visible only to its owner and permissions on the API cannot be granted to other members.
      Note If you set this parameter to Private, other members in the workspace cannot view the API in the API list.
    Label Select tags from the Label drop-down list. For more information, see Manage API tags.
    Note A tag can be up to 20 characters in length and can contain letters, digits, and underscores (_). You can configure up to five tags for an API.
    Description The description of the API. The description cannot exceed 2,000 characters in length.
    Destination Folder The directory in which you want to store the API. You can select a business process from the drop-down list. After you select a business process, a directory is generated under the business process and the API is stored in the directory. The directory is in the Business process/Business process name/API format, such as Business process/ceshi/API.
  4. Click OK.

Configure the API

  1. Double-click the API in the API list. On the tab that appears, set the Datasource Type, Datasource Name, and Table Name parameters in the Select Table section.
    Select Table
    Note
    • Before you select a table for an API, you must configure a data source in Data Integration. You can enter a table name in the Table Name field to search for the table that you want to use.
    • After you create an API, the table configuration tab automatically appears. Then, you can select a table for the API.
  2. In the Environment Configuration section, set the Memory and Function Timeout parameters.
    Environment Configuration
  3. In the Select Parameters section, configure the request and response parameters for the API.
    After you select a table in the Select Table section, all fields in the table appear in the Select Parameters section. In the Set as Req Param column, select the check boxes of the fields that you want to specify as request parameters. In the Set as Resp Param column, select the check boxes of the fields that you want to specify as response parameters. Select Parameters
    To sort the data that is returned by the API based on a specific field, find the field that you want to add and click Add in the Add to field sort column to add the field to the Sort field section. Sort field

    The sorting feature allows you to specify the fields based on which the data returned by the API is sorted. A field with a smaller sequence number in the Sort field section has a higher priority in sorting. You can click Move up or Move down to adjust the sequence of a field. You can specify the sorting mode for each field by selecting Ascending order or Descending order in the Sort column.

  4. In the right-side navigation pane, click Request Parameters. In the Request Parameters pane, configure the parameters.
    Request Parameters
    Parameter Description
    Parameter Name The name of the request parameter. The name cannot exceed 64 characters in length, and can contain letters, digits, underscores (_), and hyphens (-). The name must start with a letter.
    Bound Field The field that you want to bind to the request parameter. You cannot change the value.
    Parameter Type The type of the request parameter. Valid values: STRING, INT, LONG, FLOAT, DOUBLE, and BOOLEAN.
    Operator The operator that is used to associate or compare the value of the request parameter with the value that you specify. You can select one of the following operators:
    • Equal: The value of the request parameter is equal to the value that you specify.
    • LIKE: The value of the request parameter matches the specified pattern.
    • IN: The value of the request parameter is in the specified range.
    • NOT IN: The value of the request parameter is out of the specified range.
    • NOT LIKE: The value of the request parameter does not match the specified pattern.
    • !=: The value of the request parameter is not equal to the value that you specify.
    • >: The value of the request parameter is greater than the value that you specify.
    • <: The value of the request parameter is less than the value that you specify.
    • >=: The value of the request parameter is greater than or equal to the value that you specify.
    • <=: The value of the request parameter is less than or equal to the value that you specify.
    Note If you set Datasource Type to Table Store, you set Operator only to = in the Select Table section.
    Required Specifies whether the request parameter is required.
    Example Value The example value of the request parameter.
    Default Value The default value of the request parameter.
    Description The description of the request parameter.
    To preprocess the request parameters of the API, select Use prefilter in the Advanced Settings section. For more information, see Use prefilters.
    Note
    • Only workspaces of DataWorks Professional Edition or a more advanced edition in the China (Shanghai) region support prefilters.
    • To improve the match efficiency, specify an indexed field as a request parameter.
    • To make sure that API callers understand the details about the API, we recommend that you specify information such as the example value, default value, and description for each parameter of the API.
  5. In the right-side navigation pane, click Response Parameters. In the Response Parameters pane, configure the parameters.
    Response Parameters
    Parameter Description
    Parameter Name The name of the response parameter. The name cannot exceed 64 characters in length, and can contain letters, digits, underscores (_), and hyphens (-). The name must start with a letter.
    Bound Field The field that you want to bind to the response parameter. You cannot change the value.
    Parameter Type The type of the response parameter. Valid values: STRING, INT, LONG, FLOAT, DOUBLE, and BOOLEAN.
    Example Value The example value of the response parameter.
    Description The description of the response parameter.

    You can select Pagination and Filter in the Advanced Settings section.

    Notes on the Pagination option:
    • If you do not select Pagination, the API returns up to 2,000 records.
    • If the API returns more than 2,000 records, we recommend that you select Pagination.
    If you select Pagination, you also need to configure the following common parameters:
    • Common request parameters
      • pageNum: the number of the page to return.
      • pageSize: the number of entries to return on each page.
    • Common response parameters
      • pageNum: the page number of the returned page.
      • pageSize: the number of entries returned per page.
      • totalNum: the total number of returned entries.
    If you need to process the query results that are returned by the API, select Filter. For more information, see Use post filters.
    Note
    • Only workspaces of DataWorks Professional Edition or a more advanced edition in the China (Shanghai) region support post filters.
    • Request parameters are optional for an API. If you do not specify request parameters for an API, you must select Pagination.
  6. Click the Save icon in the toolbar.
    After the API is configured, you can test it. For more information, see Test an API.

    After the API is tested, close the Test APIs dialog box. Click Publish in the upper-right corner of the configuration tab.

    On the Service Development tab, you can find the published API in the API list. You can view the details of the API and clone or delete the API. For more information, see Manage APIs.

Switch from the codeless UI to the code editor

On the configuration tab of an API, you can switch from the codeless UI to the code editor.

  1. On the Service Development page, click the business process to which the API that you want to manage belongs.
  2. Double-click the API. The configuration tab of the API appears.
  3. Click the Switch to the code editor icon in the toolbar.
  4. In the message that appears, click OK. Then, you can view the SQL statements of the API in the Edit query SQL section.
    Notice
    • DataService Studio allows you to switch only from the codeless UI to the code editor.
    • After you switch from the codeless UI to the code editor, you cannot switch back to the codeless UI.