Create and publish a data service API
You can use natural language to instruct code agents like Qoder and CodeX to create a data service API in SQL mode from a direct data source and publish it to a production environment. This article describes the feature, its prerequisites, usage examples, and execution results. An appendix lists input information for reference.
Overview
The data service API creation and publishing feature lets you use natural language to complete the entire workflow, from creation to publication. You can query the data service projects and API groups you have access to, create an API in SQL mode from a direct data source, define request parameters with placeholders in the SQL statement, specify response parameters, and then publish the API to the production environment. After publication, you can verify the result. The published API can then be authorized for use by applications.
Use cases:
-
Quickly create an API to expose data from an existing data source by using an SQL statement.
-
Publish an API from the development state to a production environment for use by applications.
-
Verify that an API is active after it is published.
Limitations: You can currently create APIs only in SQL mode by using a direct data source. You must define request parameters by using placeholders in the SQL statement and specify the data type and whether each parameter accepts a single value or multiple values. Because creation and publication are write operations, the agent typically confirms details such as the API name, SQL statement, data source, and potential impact before execution. Published APIs can be taken offline. To delete an API, you typically must do so in the Dataphin console.
Prerequisites
-
You have a data service project and are a member of it.
-
The target data source is registered and authorized for direct API queries.
-
You have prepared the SQL statement for the API and defined its request and response parameters.
Examples
You can describe your requirements to the agent by using natural language. Here are some example commands:
-
Use this SQL to create an API in this data service project to query user information.
-
Publish the API I just created to the production environment.
-
After publishing, check if the API is active.
Interaction steps:
-
After you issue the creation command, the agent queries the data service projects and API groups you can access and asks you to confirm the target project and group.
-
The agent asks you to confirm details such as the API name, SQL statement, data source, invocation mode, and request and response parameters.
-
Because creation and publication are write operations, the agent typically asks you to confirm the changes and their impact before proceeding.
-
After publication, the agent usually queries the list of published APIs to confirm that the target API is active.
Execution results
After the operation is complete, you can expect the following results:
-
Response content: A successful creation returns the new API's ID. After a successful publication, you can find the API and its publication time in the list of published APIs.
-
Completion status: A successful response to the create and publish commands means the request was accepted.
-
Verification: You can verify that the API is active by checking if it appears in the list of published APIs with a non-empty publication time.
A successful response from the command only indicates that the request was accepted. For the definitive status, refer to the API publication status in the Dataphin console.
Appendix: Input information
The following table lists information that might be required when you create and publish a data service API. This is for reference only. In practice, the agent automatically identifies the necessary information from your commands and prompts you if anything is missing. You do not need to provide items marked as not required, as they are generated automatically.
|
Parameter |
Required |
Description |
Example |
|
Tenant ID |
Yes |
The ID of the target Dataphin tenant. |
300001413 |
|
Project ID |
Yes |
The ID of the data service project. You can obtain this ID by querying the projects that you can access. |
22 |
|
API name |
Yes |
The name of the API to be created. |
query_user_info |
|
API group |
No |
The API group for the API. If you have no specific requirements, you can use the project's default API group. |
Default API group |
|
Data source |
Yes |
The target data source for direct API queries. It must be registered and authorized. |
— |
|
SQL statement |
Yes |
The query logic for the API. Use placeholders to define request parameters. |
SELECT ... WHERE user_id = ${userId} |
|
Request parameters |
Yes |
The input parameters that correspond to the SQL placeholders. You must specify the name, data type, and whether it is a single-value or multi-value parameter. |
userId (STRING, single-value) |
|
Response parameters |
Yes |
The list of fields returned by the API and their data types. |
user_id, user_name |
|
Request type |
Yes |
The operation type of the API, such as single-record query, list query, create, or update. |
List query |
|
Invocation mode |
No |
Synchronous or asynchronous. The default is synchronous. |
Synchronous |
|
Version number |
No |
The initial version number of the API. The API is published with this version. |
1.0.0 |