Creating a Function API
Overview
ROMA Connect allows you to define custom functions as backend services and open up function capabilities as APIs.
Prerequisites
- If a backend service needs to use a signature key for authentication, create a signature key first.
- If you need to use the custom mode for API security authentication, create a custom authorizer first.
Procedure
- Log in to the ROMA Connect console. On the Instances page, click View Console of an instance.
- Create a backend.
- In the navigation pane on the left, choose API Connect > Custom Backends. On the Backends tab page, click Create Backend.
- On the Create Backend page, set backend parameters and click Create.
Table 1 Backend request information Parameter
Description
Name
Enter a backend name. It is recommended that you enter a name based on naming rules to facilitate search.
Integration Application
Select the integration application to which the backend belongs. If none is available, click Create Integration Application on the right to create one.
Backend Request Method
Select the request method of the backend. The value can be GET, POST, PUT, or DELETE.
Backend Request Path
Enter the request path of the backend, in the /getUserInfo/userId format.
The value of Request Path is case sensitive.
Backend Security Authentication
Select the security authentication mode of the backend.
- Signature key: A signature key is used to authenticate the request sender. If a signature key is used for authentication, the same signature key must be bound to the API that calls the backend service.
- None: No authentication is required for calling requests.
Description
Enter a brief description of the backend.
Advanced Settings
Version
Enter the backend version, for example, V1.0. Custom backend version numbers differentiate the backend services.
Input Parameters
Define request parameters of the backend service.
In the Input Parameters area, click Add Input Parameter and add request parameters of the custom backend.
- Name: name of a request parameter, which is user-defined.
- Parameter Location: location of the request parameter in the backend request. The value can be Headers or Parameters.
- Default Value: default value of the parameter, used only in the subsequent custom backend test procedure. This parameter does not take effect during custom backend deployment.
- Mandatory: whether a request parameter is mandatory in a backend request.
- Description: Enter the description of the parameter.
Returned Type
Select the response data format of the backend. The value can be JSON, XML, or STREAM.
Formatting
This parameter specifies whether to format the response message body based on the selected return type.
After the backend is created, the online IDE of the backend is automatically displayed. The backend type is data backend by default.
- Configure a function backend.
- In the upper left corner of the online IDE, choose File > New Function Backend > Blank Template. In the dialog box displayed, click Yes to switch the backend type to function backend.
- Edit the function script in the editing box on the right. You can also edit the function script using the script example provided by the system.
For details, see Developing Custom Function Backends
The maximum script size supported by a function API is 32 KB.
- Click Save in the upper right corner of the page to save the function backend configuration.
- Test the backend functions.
In the upper right corner of the page, click Test. In the Test Parameters area, add request parameters based on the definition of the backend service and click Test to send the request.
- In the Execution Result area, view the response of the backend.
- In the Execution History area, view the historical test records of the backend. Click a test record to import historical test parameters to the test parameter list on the left and perform the test again.
- Deploy the backend.
After the backend test is complete, click Deploy in the upper right corner of the page. In the dialog box displayed, click Yes to deploy the backend.
- Publish a function API.
- Click Publish in the upper right corner of the page.
- On the page displayed, configure API information and click Publish to create a frontend function API for the backend and publish the API in the environment.
Table 2 Parameters for publishing an API Parameter
Description
API Group
Select an API group for the frontend API. If none is available, click Create API Group on the right to create one.
NOTE:The API group cannot be changed once set and is bound to the access domain name of the API.
Environment
Select the environment in which the API is to be published. If your required environment is not available, click Create Environment on the right to create one.
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 the token or AK/SK.
- Custom: The custom function API is used for authenticating API requests.
- None: Authentication is not required for API requests.
Custom Authorizer
This parameter is mandatory only if Frontend Security Authentication is 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 HTTP, HTTPS, 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.
Retry Times
Number of retry times after ROMA Connect fails to call the backend service.
- If the value is -1, the retry function is disabled. However, requests will be retried once by default except for those using POST and PATCH.
- 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 value of Request Path is case sensitive.
CORS
This parameter specifies whether CORS is supported for the API.
For security purposes, the browser restricts the cross-domain requests from being initiated from a page script. In this case, the page can access only the resources from the same source. CORS allows the browser to send XMLHttpRequest requests to the server in a different domain. For details about CORS, see Configuring CORS for APIs.
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