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
- Create a backend.
- In the navigation pane on the left, choose API Connect > Custom Backends. On the Backends tab, click Create Backend.
- 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.
- Configure and deploy the data backend.
- In the upper left corner, choose New Data Backend > Add Data Source.
- 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.
- 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";
- Click Save in the upper right corner of the page to save the backend configuration.
- 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}]}
- 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.
- Publish the data API.
- After the backend deployment is complete, click Publish in the upper right corner of the page.
- 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.
- Bind an independent domain name to the data API.
- 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.
- 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.
- (Optional) For HTTPS-compatible data APIs, bind an SSL certificate to their independent domain name.
- Click Select SSL Certificate on the right of the independent domain name.
- Select an SSL certificate and click OK.
If none is available, click Create SSL Certificate to create one.
- Switch to the APIs tab and obtain the API request method and URL for external applications to call the API.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot