Generating Script APIs
This section describes how to generate an API in the script mode.
To meet personalized query requirements of users, DLM also supports the API generation in the custom SQL script mode. It allows you to compile API query SQL statements and provides multi-table join, complex query conditions, and aggregation functions.
Configuring Basic API Information
- Log in to the DGC console, select a DGC instance, and click Access.
On the displayed page, click the Workspaces tab. In the workspace list, locate the required workspace.
- Click Data Lake Mall of the corresponding workspace.
Navigate to the Data Lake Mall console.
- Choose APIs > Create. On the displayed page, enter the basic information.
Table 1 API basic info Parameter
Description
API
An API name consists of 3 to 64 characters and starts with a letter. Only letters, digits, and underscores (_) are allowed.
API Catalog
An API catalog is a set of APIs with a specific function or scenario. It is the minimum organization unit of APIs in DLM and the minimum management unit of the API gateway.
Click Select Catalog to create an API catalog or select an existing one created in Managing an API Catalog.
Request Path
The path for accessing an API.
Example: /v2/{project_id}/streams.
Parameter Protocol
A parameter protocol is used to transmit requests. HTTP and HTTPS are supported.
Request Mode
HTTP defines the following request modes that can be used to send a request to the server:
GET requests the server to return specified resources.
POST requests the server to add a resource or perform special operations.
Description
A brief description of the API to be created.
Tag
The tag set for an API. A maximum of 20 tags can be set for an API.
Reviewer
An owner who has permissions to review APIs.
Click Add new to enter the page. On the displayed page, choose > .
Security Authentication
Security authentication mode, which can be:
- App Authentication: API Gateway authenticates API requests.
- IAM Authentication: IAM authenticates API requests.
- None-authentication: No authentication is required.
Display Scope
After the API is published, all users in the selected scope can view the API in the service catalog.
- Current workspace APIs
- Current project APIs
- Current tenant APIs
Access Log
If this parameter is selected, you can view the generated API query results that will be kept for seven days on the Access Logs page.
Min. Retention Period
Minimum duration reserved before API unbinding. Before an API developer suspends, brings offline, or cancels the authorization of an API, the system notifies the authorized API callers and reserves at least X hours for them to unbind the API. During the retention period, the API can be used if it is not unbound. The value 0 indicates that there is no minimum retention period.
Input parameter
Input parameter is a set of parameters in the API request, including dynamic parameters in the resource path, query parameters in the request URI, and header parameters.
The following is an example that describes the dynamic parameters in the resource path (request path):
/v2/{project_id}/streams, where {project_id} is a dynamic parameter that needs to be configured.
- Click Add and enter project_id for Name.
- Set Parameter Location to PATH.
- Set Type to STRING.
- Set Example Value and Description as required.
- After the basic API information is complete, click Next to go to the Data Extract Logic page.
Configuring the Data Extraction Logic
- Select a data source, data connection, database, and queue to obtain the tables to be configured.
Currently, only DWS, DLI, HBASE, HIVE, MySQL and RDS data sources are supported. Configure data sources in DGC Management Center in advance and enter SQL statements as prompted.
- Compile a SQL statement to query APIs.
On the script editing page, enter the SQL statement as prompted.
- The fields queried by the SELECT statement are parameters returned by APIs.
- The parameters in the WHERE statement are parameters requested by APIs. The format is ${parameter name}.
- Select a pagination mode.
- Add ranking parameters.
In the list of ranking parameters, set whether the ranking parameters are optional, set the ranking mode, and enter the description.
Click
to add the input and ranking parameters to the API requests of the SQL statement.
Before adding ranking parameters, ensure that the SQL statement is correct.
- Edit request parameters.
After the SQL statement is compiled, click Test SQL and bind the HTTP input parameters on the database field tab page. Set pre_order_by by referring to 6 in Configuring the Data Extraction Logic.
pre_order_by is optional. If pre_order_by is not set, use the mandatory fields as the ranking criterion.
Testing an API
After all parameters are set, click Debug. Enter the values for parameter Value and click Debug in the lower left corner. You can view the Request and Response details on the right part of the displayed page. If the test fails, follow the instructions as prompted and restart the test. During the configuration, pay attention to the settings of the normal response example.
After the test is complete, click OK.
Last Article: Generating Wizard APIs
Next Article: Registering APIs
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.