Create an API from a Dataphin table (wizard mode)
Wizard mode lets you create an API from a Dataphin logical table by using a visual interface to configure API parameters. This topic describes how to create an API by using wizard mode.
Prerequisites
You have created a logical table. The logical table can be a dimension logical table, a fact logical table, or a summary logical table. For more information, see data modeling.
You have configured a synchronization task for the logical table in the integration module. The following conditions apply:
The destination of the synchronization task must be a data source supported by DataService. You must have read permissions for this data source.
In O&M > Periodic Tasks, find the task that corresponds to the logical table, and choose Backfill Data > Backfill Current and Downstream Tasks. Select 6 for the task dependency level, select all tasks in the list, and then verify that the data backfill instance completed successfully. For more information, see Data backfill for periodic tasks.
In Ad Hoc Query, verify that the data is correct and that the logical table is not empty. For more information, see Query and download data.
In the integration module, configure a synchronization task. For the input component, select LogicalTable Input Configuration (LogicalTable). For the output component, select MySQL writer. For more information, see Configure the LogicalTable reader and Configure the MySQL writer.
After you configure and publish the synchronization task, you can create, submit, and publish the logical table API in DataService.
Limitations
Creating an API from a logical table is subject to computing engine restrictions. For information about supported computing engines, see Data sources and computing engines supported by DataService.
Permissions
Both service project administrators and development users can create APIs.
Usage notes
The request parameters and response parameters of an API must be from the same logical table. Otherwise, the API will not function correctly.
Step 1: Choose an API creation method
In the top navigation bar on the Dataphin homepage, choose Service > API Development.
In the upper-left corner, select a project. In the left-side navigation pane, click API Service. On the API page, click + Create API.
In the Create API dialog box, select Logical Table API-Wizard Mode.
Step 2: Configure API parameters
On the Create API page, configure the basic information and parameters for the API.
Basic information
Parameter
Description
API name
The name of the API. The name must meet the following requirements:
Can contain Chinese characters, letters, digits, and underscores (_).
Must be 4 to 100 characters in length.
Must start with a letter.
Must be globally unique.
Operation type
The operation type. Valid values are GET and LIST:
GET: Requests a specific resource from the server.
LIST: Requests a subset of resources from the server.
Data update frequency
The update frequency of the API's response data. This helps callers understand the data freshness. You can select Daily, Hourly, Per Minute, or Custom. If you select Custom, you can enter a string of up to 128 characters.
API group
Select an API group from the current project. To create an API group, see Create a service group.
Description
A brief description of the API. The description can be up to 128 characters.
Protocol
The protocol for the API. HTTP and HTTPS are supported.
HTTP: HyperText Transfer Protocol. It is the most widely used network protocol.
HTTPS: If the gateway is configured as an Alibaba Cloud API Gateway dedicated or shared instance, you can select the HTTPS protocol. To ensure the API is accessible, ensure the SSL certificate for your custom domain is valid. To configure an SSL certificate, choose Platform Management > Network Configuration and configure the certificate on the Network Configuration page.
Timeout
The timeout for an API call, in seconds. This value must be an integer from 3 to 60. The default is 3.
If an API call exceeds the configured timeout, the call fails and returns an error. This helps you detect and handle API call exceptions promptly. For more information about how to view exceptions, see Manage O&M monitoring APIs.
Cache settings
You can Enable or Disable the cache. If enabled, you must set the Cache Duration. The default value is 300 seconds. You can set the duration to an integer from 60 to 1,000,000 seconds (approximately 277.78 hours).
Version
The API version. It must be unique within the API and is used to track configuration changes. The version must meet the following requirements:
Cannot exceed 64 characters in length.
Can contain uppercase and lowercase letters, digits, underscores (_), periods (.), and hyphens (-).
Return type
The default value is JSON.
Request and response parameters
When you configure API Request Parameters and Response Parameters, you first need to determine the source of the API's request and response parameters (Logical Table), then add the request parameters to the Request Parameters area and the response parameters to the Response Parameters area, and finally configure the basic information for the Request Parameters and Response Parameters.
In the Parameter Configuration section, after you select a logical table, all fields from that table appear.
Parameter
Description
Mode
Basic and Dev-Prod modes are supported.
In Basic mode, the API reads the production database during development, submission, and in production.
In Dev-Prod mode, the API reads the development database during development and submission, and reads the production database after it is deployed.
Logical table fields
Select the logical table's business segment, and then select the logical table. You can add all fields or individual fields.
Hover over a Dataphin logical table field and click Request Parameters or Response Parameters to add the field to the Request Parameters or Response Parameters list on the right.
Parameter
Description
Request parameters
Parameter name
The external parameter name used in an API request. The name must meet the following requirements:
Can contain letters, digits, and underscores (_).
Must start with a letter.
Must be 1 to 64 characters in length.
Mapped field
The logical table field that this parameter maps to. This field is not visible to callers.
Parameter type
The data type of the parameter. Supported types include double, float, string, Date(yyyy-MM-dd HH:mm:ss), Boolean, int, long, short, byte, BigDecimal, and binary.
The parameter type must match the corresponding field type in the logical table. If the exact type is unavailable, we recommend that you select String.
Operator
The operator used to filter data based on the parameter. For more information about supported operators, see Operators supported in API development.
Example
An example value to help developers use the parameter correctly. For example, if the parameter name is ID, the parameter type is Int, and the operator is =, you can enter 5 as the example. The example can be up to 1,000 characters in length.
Description
A brief description of the request parameter, up to 1,000 characters long.
Required
Specifies whether the parameter is required for an API call.
If you select No, the API call succeeds even if this parameter is omitted.
If you select Yes, the API call fails if this parameter is omitted from the request.
For example, assume that
idis a required request parameter andnameis a response parameter.This statement returns the corresponding
nameand its value:select name from tableA where id=5;This statement reports an error because the required
idparameter is missing:select name from tableA;
Response parameters
Parameter name
The external parameter name that the API returns. The name must meet the following requirements:
Can contain letters, digits, and underscores (_).
Must start with a letter.
Must be 1 to 64 characters in length.
Mapped field
The logical table field that this parameter maps to. This field is not visible to callers.
Parameter type
The data type of the returned data. Supported types include double, float, string, Date(yyyy-MM-dd HH:mm:ss), Boolean, int, long, short, byte, BigDecimal, and binary.
The parameter type must match the corresponding field type in the logical table. If the exact type is unavailable, we recommend that you select String.
Example
An example value for the response parameter to help developers understand the output, up to 1,000 characters long.
Description
A brief description of the response parameter, up to 1,000 characters long.
Click Submit to create the API.
Next steps
After creating the API, test and publish it to the DataService market to make it available to applications. For more information, see Test and publish an API.
To perform operations such as deleting the API, managing versions, or transferring ownership, see Manage APIs.