Updated on 2023-08-28 GMT+08:00

Creating and Opening a Data API

Overview

Through the data API, the parking space status data in the parking lot management system is opened to third-party applications so that vehicle owners and transportation departments can learn about the parking space status.

Procedure

  1. Create a backend.
    1. In the navigation pane on the left, choose API Connect > Custom Backends. On the Backends tab, click Create Backend.
    2. Set backend parameters and click Create.
      Table 1 Backend configuration

      Parameter

      Description

      Name

      Backend name.

      Integration Application

      Select the integration application created in Registering a Device on ROMA Connect.

      Backend Request Method

      Request method of the backend. Set this parameter to GET here.

      Backend Request Path

      Enter the request path of the backend in the /serviceName/interfaceName format.

      Backend Security Authentication

      Security authentication mode of the backend. Set this parameter to None here because the API to open and the backend service are in the same instance in this practice.

      Description

      Enter a brief description of the backend.

      Advanced Settings

      Retain the default settings in the Advanced Settings area.

      After the backend is created, the online IDE of the backend is automatically displayed. The backend type is data backend by default.

  2. Configure and deploy the data backend.
    1. In the upper left corner, choose New Data Backend > Add Data Source.
    2. On the Add Data Source page displayed, configure data source information and click Add.
      Table 2 Data source configuration

      Parameter

      Description

      Select Data Source

      Select the MySQL data source connected in Creating an MQS-to-Database Integration Task.

      Select Statement Type

      Select the type of the statement to be executed. In this example, select SQL.

      Advanced Settings

      Retain the default settings in the Advanced Settings area.

    3. After adding a data source, select the data source on the left of the online IDE and add the following statement to the statement editing box on the right to obtain the number of vacant parking spaces from the database.
      The following statement assumes that the name of the data table that stores parking space information and parking space status information is ParkingData, and the parking space status field in the table is Status in the MySQL database.
      SELECT COUNT(Status) AS FreeNo FROM ParkingData WHERE Status="0";
    4. Click Save in the upper right corner of the page to save the backend configuration.
    5. Click Test in the upper right corner of the page, and then click Test in the Test Parameters pane below.

      In the Execution Result column, check whether the following JSON data is returned. xxx indicates the number of vacant parking spaces.

      {"default":[{"FreeNo":xxx}]}
    6. After the backend is tested, click Deploy in the upper right corner of the page. In the dialog box displayed, click Yes to deploy the data backend.
  3. Publish the data API.
    1. After the backend deployment is complete, click Publish in the upper right corner of the page.
    2. On the page displayed, set the parameters and click Publish to create a frontend API for the backend and publish the API in an environment.
      After the API is published, the API details page is displayed.
      Table 3 Parameters for publishing a backend

      Parameter

      Description

      Group

      Select an API group for the frontend API. If no API group is available, click Create API Group on the right to create one.

      Environment

      Select the default environment RELEASE.

      Frontend Security Authentication

      Select the authentication mode of the API. The App authentication mode is recommended.

      • App: ROMA Connect authenticates API requests. When calling an API, a user gets authenticated using the key and secret of an integration application.
      • IAM: IAM authenticates API requests. When calling an API, a user gets authenticated using a token or an AK/SK pair.
      • Custom: The custom function API is used for authenticating API requests.
      • None: Authentication is not required for API requests.

      Custom Authorizer

      Mandatory for Frontend Security Authentication set to Custom.

      Select a frontend custom authorizer you have created.

      Frontend Request Protocol

      Select the request protocol used by the frontend API. The value can be HTTPS, HTTP, or HTTP&HTTPS. HTTPS is recommended for transmitting important or sensitive data.

      Timeout (ms)

      Enter the timeout interval of a backend service request. The default value is 60000.

      Retries

      Number of retries after ROMA Connect fails to call the backend service.

      • If the value is -1, this parameter is disabled.
      • If the value ranges from 0 to 10, this parameter is enabled, and retries are performed based on the configured value.

      Advanced Settings

      Frontend Request Method

      Select the request method of the frontend API. ANY indicates that the API can be accessed using any request method.

      Frontend Request Path

      Enter the request path of the frontend API, for example, /getUserInfo/userId.

      The request path is case sensitive.

      CORS

      Whether the API supports cross-origin resource sharing (CORS). In this example, disable this parameter.

  4. Bind an independent domain name to the data API.
    1. On the API details page displayed after you publish the API, choose Group Information and click Bind Independent Domain Name in the Independent Domain Names area.
    2. In the displayed dialog box, enter the domain name and click OK.
      Table 4 Independent domain name configuration

      Parameter

      Description

      Domain Name

      Enter the domain name to be bound.

      Minimum TLS Version

      The minimum TLS version that can be used to access the domain name.

      HTTP-to-HTTPS Auto Redirection

      Whether to support HTTP-to-HTTPS redirection.

      Redirection takes effect only when the API request protocol is HTTPS or HTTP&HTTPS and an SSL certificate has been bound to the independent domain name.

      NOTE:

      Redirection is only suitable for GET and HEAD requests. Redirecting other requests may cause data loss due to browser restrictions.

    3. (Optional) For HTTPS-compatible data APIs, bind an SSL certificate to their independent domain name.
      1. Click Select SSL Certificate on the right of the independent domain name.
      2. Select an SSL certificate and click OK.

        If none is available, click Create SSL Certificate to create one.

  5. Switch to the APIs tab and obtain the API request method and URL for external applications to call the API.