You can register existing APIs in DataService Studio to manage, publish, and integrate the APIs in a uniform manner. This topic describes how to register and configure an existing API.
Register an API
If you have no APIs, you must create an API. For more information, see Create an API in the codeless UI.
- Go to the DataService Studio page.
- Log on to the DataWorks console.
- In the left-side navigation pane, click Workspaces.
- In the top navigation bar, select the region where the target workspace resides. Find the target workspace and click DataService Studio in the Actions column.
- On the Service Development tab, move the pointer over the icon and select Register API.
You can also click the required business process, right-click API, and then choose .
- In the Register API dialog box, set the parameters as required.
Parameter Description API Name The name must be 4 to 50 characters in length and can contain letters, digits, and underscores (_). It must start with a letter. API Path The path for storing the API, such as /user.Note The path can be up to 200 characters in length and can contain letters, digits, underscores (_), and hyphens (-). It must start with a forward slash (/). Protocol Valid values: HTTP, HTTPS, and HSF.
If you need 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. In addition, you must upload a Secure Sockets Layer (SSL) certificate in the API Gateway console. For more information, see Enable HTTPS for an API operation.
Request Method Valid values: GET, POST, PUT, and DELETE. Response Content Type Valid values: JSON and XML. Visible Range Valid values: Work Space and Private.
- 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 users.
Note If you set the Visible Range parameter to Private, the API is visible only to you in the API list. Other members in the workspace cannot view the API in the API list.
Label Select tags from the Label drop-down list.Note A tag can be up to 20 characters in length and can contain letters, digits, and underscores (_). You can set at most five tags for an API. Description The description of the API. The description can be up to 2,000 characters in length. Target Folder The folder for storing the API.
- Click OK.
Configure the API
- Double-click the registered API. On the configuration tab of the API, set the parameters as required in the Define the back-end Service section.
Parameter Description Back-end Service Host The host of the registered API. The hostname must start with http:// or https://, and cannot contain the path. Back-end Service Path The path of the registered API. The path can contain parameters that are enclosed in brackets . Example: /user/[userid].
In the next step, parameters that are defined in the Back-end Service Path parameter are automatically added to the request parameter list.
Back-end Service Timeout The timeout period of the backend service.
- In the Define Request Parameters section, set the parameters as required.
Parameter Description Request Parameters You can click Add Parameters to add a request parameter for the API.
For each request parameter, you can set the Parameter Position field to QUERY, HEAD, or BODY. The valid values of the Parameter Position field vary based on the request method that is used by the API. Select one from the valid values that are displayed.
Constant Parameters Constant parameters have fixed values and are invisible to API callers. The constant parameters do not need to be specified during an API call. However, the backend service receives the defined constant parameters and their values in each API call.
The constant parameters are applicable when you need to fix the value of a parameter or hide the parameter from API callers.
Request Body Description This parameter is displayed only when you set the Request Method parameter to POST or PUT.
In the Request Body Description parameter, you can enter the body description in the JSON or XML format. This way, you can provide an example of the request body for API callers to determine the format of the request body.
- In the Define Response Content section, set the Correct Response Example and Error Response Example parameters. These examples are reference for API callers to write the code for parsing the results of the API.
- In the Error Codes section, set the Error Code, Error Message, and Solution parameters to define an error code. The information helps API callers diagnose the error causes.
- Click the 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.