Updated on 2024-04-03 GMT+08:00

Registering APIs

This document describes how to use DataArts DataService to register existing service APIs with API Gateway, publish these APIs, and centrally manage these APIs and the APIs created in DataArts DataService.

DataArts DataService Shared supports the registration of RESTful APIs using GET and POST methods.

Configuring Basic API Information

  1. On the DataArts Studio console, locate an instance and click Access. On the displayed page, locate a workspace and click DataArts DataService.
    Figure 1 DataArts DataService

  1. In the left navigation pane, choose DataArts DataService Shared. The Overview page is displayed.
  2. In the left navigation pane, choose API Development > APIs. In the right pane, click Register and configure basic API information.
    Table 1 API basic configuration

    Parameter

    Description

    API

    An API name consists of 3 to 64 characters and starts with a letter. Only letters, numbers, 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 DataArts DataService and the minimum management unit of API Gateway.

    Click Select Catalog to create an API catalog or select an existing one created in Creating an API Directory.

    Request Path

    The path for accessing an API.

    Example: /v2/{project_id}/streams.

    Protocol

    A protocol 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 resources or perform special operations. This method is recommended for API registration. The POST request does not have a body. Instead, it involves transparent transmission.

    Description

    A brief description of the API to be registered.

    Tag

    The name of the tag. Only letters, numbers, and underscores (_) are allowed. Tag names cannot start with underscores (_).

    Reviewer

    An owner who has permissions to review APIs.

    Click Add to enter the Review Center page. On the page displayed, click Add on the Reviewer Management tab page to add a reviewer.

    Security Authentication

    When creating an API, you can select one of the following authentication modes. The three modes differ in how the API is called. You are advised to use App Authentication, which is more secure that the other two modes.
    • App authentication: App authentication is used for calling an API. The AppKey & AppSecret is used for authentication. It is highly secure.

      When App authentication is used, an SDK is required for access. Java, Go, Python, JavaScript, C#, PHP, C++, C, and Android SDKs are available. For details about how to call APIs in each language, see Calling APIs Through App Authentication.

    • IAM authentication: IAM authenticates API requests. This mode is available only for Huawei cloud users. The security level is medium.

      When using IAM authentication, you need to call the Obtaining a User Token API of IAM to obtain a token, add the X-Auth-Token parameter with the obtained token as the value to the request header, and use an API calling tool or SDK to call released APIs.

    • Non-authentication: No authentication is required. This mode allows all users to access APIs, which may pose security risks. It is recommended only for testing APIs. If the caller is not a trusted user, there is a risk of data leakage, breakdowns caused by high concurrent access, SQL injection, and others.

      This mode does not require any authentication information. You can use an API calling tool or SDK to directly call an API by specifying required parameters.

    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's APIs

    Access Log

    If you select this option, the API query result will be recorded and retained for seven days. You can choose Operations Management > Access Logs and select the request date to view the logs.

    Min. Retention Period

    Minimum duration reserved before API unbinding. Before an API developer suspends, unpublishes, 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.

    1. Click Add and enter project_id for Name.
    2. Set Parameter Location to PATH.
    3. Set Type to STRING.
    4. Set Example Value and Description as required.
  3. After the basic API information is complete, click Next to go to the Data Extract Logic page.

Configuring API Parameters

After configuring basic API information, you can set API parameters. The following describes how to configure the API backend services and request parameters.

Table 2 API parameters

Parameter

Description

Protocol

A protocol used to transmit requests. HTTP and HTTPS are supported.

This parameter is used by DataArts DataService to transmit requests to the APIs to be registered.

Request Mode

HTTP defines the following request modes that can be used to send a request to the server. This parameter is used by DataArts DataService to transmit requests to the APIs to be registered.

GET requests the server to return specified resources.

POST requests the server to add resources or perform special operations.

Backend Service Host

Host of the API to be registered. The value cannot start with http:// or https:// and cannot contain Path.

Backend Service Path

Path of the API to be registered. The path can contain parameters placed in {}, for example, /user/{userid}.

Backend Timeout (ms)

Backend timeout interval.

Backend Service Parameter

The optional parameters can be placed in PATH, Header, and Query. The positions of optional parameters vary depending on the request mode. Select a parameter position as required.

Constant Parameter

Constant parameter is the fixed parameter invisible to the caller. Constant parameter does not need to be transferred during API calling. However, the background service always receives the constant parameter and parameter value defined here. This parameter applies to scenarios in which you want to set a parameter of an API to a fixed value and hide the parameter from the caller.

Testing an API

After setting and saving all parameters, click Next.

Specify Value and click Debug. You can view the Request and Response details on the right part of the displayed page.
  • During the test, if the DataArts DataService API does not return a query result within 30 seconds (default value), a timeout error is reported.
  • If the test fails, follow the instructions as prompted and restart the test.

After the test is complete, click OK.