Updated on 2023-07-26 GMT+08:00

Creating a Function API

Overview

ROMA Connect allows you to define custom functions as backend services and open up function capabilities as APIs.

Prerequisites

Procedure

  1. Log in to the ROMA Connect console. On the Instances page, click View Console next to a specific instance.
  2. Create a backend.
    1. In the navigation pane on the left, choose API Connect > Custom Backend. On the Backends tab page, click Create.
    2. 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 no integration application 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

      Select the backend version, for example, 1.0.

      Input Parameters

      Define request parameters of the backend service based on the site requirements.

      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: It is used as the default test value of parameters only in the subsequent custom backend test procedure. This parameter does not take effect during custom backend deployment.
      • Mandatory: specifies 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.

  3. Configure a function backend.
    1. 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.
    2. Edit the function script in the editing box on the right. You can also use the script example provided by the system to edit the function script.

      For details about how to compile function API scripts, see Developing Function APIs.

    3. Click Save in the upper right corner of the page to save the function backend configuration.
  4. 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.
  5. 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.

  6. Publish a function API.
    1. Click Publish in the upper right corner of the page.
    2. 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 the API group to which the corresponding API belongs. If no API group is available, click Create API Group on the right to create one.

      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.

      Backend Security Authentication

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

      • App: ROMA Connect authenticates API requests. When a user calls the API, the key and secret of the integration applications are used for authenticating API requests.
      • IAM: IAM authenticates API requests. When a user calls an API, the token or AK/SK is used for authenticating API requests.
      • 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.

      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, in the /getUserInfo/userId format.

      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.