This article introduces you to the steps that script mode can take to generate the API.
To meet the needs of high-end users for personalized queries, the Data Service also provides a script pattern for customizing SQL, allows you to write your own SQL queries for the API, multi-Table Association, complex query conditions and Aggregate functions are supported.
Configure the API basic information
- Navigate to the .
- Click Script Mode to fill in the API basics.
Note the settings for the API grouping during configuration. An API group includes a collection of APIs that are used for a specific scenario. It is the minimum management unit in API Gateway. In the Alibaba Cloud API Marketplace, each API group corresponds to a specific API product.
Note The set up example for API grouping is as follows:
For example, you would like to configure an API product for weather inquiry, weather search API by city name weather search API, scenic spot name search weather API and zip search weather API three kinds of APIS, then you can create an API group called a weather query, and put the above three APIs in this group. The API is shown as a weather query product when published to the marketplace.
Of course, if your generated API is used in your own app, you can use grouping as a classification.
Currently, the build API only supports HTTP protocol, GET request mode, and JSON return type.
- After providing the API basic information, click Next to go to the API parameter configuration page.
Configure the API Parameters
- Select the data source and table.
Navigate to the, click the appropriate table name in the data table list, you can view the field information for this table.
- You need to configure the data source in advance in the data set formation.
- You must select a data source. Table join queries across data sources are not supported.
- Write SQL queries for the API.
You can enter the SQL code in the code box on the right side. The system supports one-click SQL function, checking fields in the list of fields, and clicking Generate SQL, the SQL statement for
SELECT xxx FROM xxxis automatically generated and inserted at the right cursor.
- One-click SQL addition is especially useful when the number of fields is relatively large, which can greatly improve the efficiency of SQL writing.
- The field of the SELECT query is the return parameter of the API, the parameter at the where condition is the request parameter for the API, And the request parameter is identified with $.
- Finally, edit and complete parameter information.
After writing the API query SQL, click the parameters in the upper-right corner to switch to the parameter information Edit page, you can edit the type, sample values, default values, and descriptions of the parameters here, where Type and description are required.
Note To help the caller of the API get a more comprehensive understanding of the API, please complete the API parameter information as much as possible.
- If you do not enable the response pagination, the API outputs up to 500 records by default.
- If the return result may exceed 500, turn on the response pagination function.
- Common request parameters
- pageNum: the current page number.
- Pagesize: The page size, that is, the number of records per page.
- Common response parameters
- pageNum: the current page number.
- pageSize: The page size, that is, the number of records per page.
- totalNum: the total number of records.
| SQL rule prompt.
When the configuration of the API parameters is complete, click Next to enter the API testing section.
Set parameters and click Start Test to send the API request online. The API request details and response are displayed on the right. If the test fails, read the error message carefully and make the appropriate adjustments to test your API again.
After completing the API test, click Finish. The data API is successfully created.