Manage application APIs

更新时间:
复制 MD 格式

API management lets you centrally manage your application's API definitions. It can scan for APIs based on code annotations, such as @RestController, and report them to the platform. This topic describes how to configure API management rules and create APIs and data models.

Create or import APIs

Create an API

  1. Log in to BizWorks, in the select Platform drop-down list selected microservice Development Platform.

  2. Click the image.pngicon or the text box in the upper-right corner of the page. From the drop-down list, click the name of the project that you want to view and click the Applications tab. On the Applications page, click the name of the application that you want to view. image

  3. In the left-side navigation pane, choose Application Development > Interface Management.

  4. On the application API management page, select New > Create API.

  5. In the Create API panel, configure the API Name, API Path, and Request Parameters, and then click Save . The basic information also includes the Directory and OperationId fields, and a Description text box. The supported request parameter types are Query Parameters, Path Parameters, and Header Parameters.

    Note
    • Register with Gateway

      For new APIs, such as those created by importing, reverse scanning, or automatic model generation, this option is enabled by default.

      • Registering an API with a gateway provides a unified entry point for access from outside the cluster and enables security protection.

      • If you enable gateway registration for an API, it is registered with the corresponding gateway service during deployment. This requires the application to be in an environment with a configured gateway. For gateway instance details, see your project's environment and cluster information.

      • If you do not enable this option, the API is not registered with the gateway during deployment. Consequently, it can be accessed only from within the cluster, and its information is not automatically synchronized to the open platform.

      • You must redeploy the application for the changes to take effect.

    • Enable Authentication

      • This feature requires the API to be registered with the gateway service to take effect.

      • When an application API is registered with the gateway during deployment, the platform uses this field to determine whether to enable security authentication.

      • If set to Default, whether security authentication is enabled depends on the global API configuration.

      • If set to Enabled, security authentication is enforced for the API in all environments, regardless of the global configuration.

      • If set to Disabled, security authentication is disabled for the API in all environments, regardless of the global configuration.

      • You must redeploy the application for the changes to take effect.

  6. Optional: Create a data model and a directory.

    Create a data model

    1. On the application API management page, select New > Create Data Model.

    2. In the Create Data Model panel, configure the settings and click Save.

    Create a directory

    1. On the application API management page, select New > Create Directory.

    2. In the Create Subdirectory dialog box, configure the settings and click Add.

  7. Optional: In the Actions column for the target API, click View, or click the target API or data model in the left-side navigation pane. The left pane displays the API directory structure in a tree view. The right pane lists information for each API, including Method, Path, Description, Register with Gateway, Enable Authentication, and Last Updated.

    The Details page for the target API or data model has three tabs: Details, Run, and Mock. The Details tab shows basic information such as the API path, last updated time, gateway registration status, and authentication status, as well as the definitions for request and response parameters. The Generate Code, Edit, and Delete buttons are in the upper-right corner.

  8. Optional: In the upper-right corner of the API's Details page, select Generate Code > Generate API Definition Code or Generate Code > Generate API Request Code.

Import APIs

  1. On the application API management page, select New > Import APIs.

  2. In the Batch Import panel, click or drag the target Swagger file into the dashed box (only OAS 2.0 is supported). Then, click Start Import.

Edit an API

  1. On the application API management page, click Edit in the Actions column for the target API.

  2. In the Edit API panel, modify the settings and click Save.

Batch delete APIs

  1. On the application API management page, select one or more APIs. The checkbox for each selected row shows a blue check mark, and the Batch Delete button at the top of the page becomes available. Then, click Batch Delete.

  2. In the confirmation dialog box, click Delete.

Delete an API

  1. On the application API management page, click More > Delete in the Actions column for the target API.

  2. In the confirmation dialog box, click Delete.

Debug APIs

  1. On the application API management page, click More > Debug in the Actions column for the target API.

  2. From the Online Debugging drop-down list, select the target environment. Configure the parameters as needed, and then click Send Request. The page includes Advanced Settings, where you can enable API call credential configuration and domain binding. In the request parameters section, you can configure the HTTP Method, Path, and four types of parameters: Query, Path, Body, and Headers. The Body parameter supports tree and code editing modes. At the bottom, the page provides Save and Reset Parameters buttons.

    If the page displays a message indicating that the application has not been deployed in this environment, you must deploy it before you can start debugging. Click Deploy Now. For subsequent steps, see Deploy a central application instance. In this case, the Send Request button is disabled.

Manage mock

Enable mock

  1. On the application API management page, click the name of the target API.

  2. Click the Mock tab, and then click Enable Mock.

  3. In the Edit Mock Configuration panel, select an HTTP Status Code, configure the settings as needed, and then click Save. The HTTP Status Code drop-down list supports options such as 200 - OK, 201 - Created, 401 - Unauthorized, 403 - Forbidden, and 404 - Not Found. Below, under the Body and Header tabs, you can click Generate Sample Value to automatically populate the return value or manually edit it in JSON format.

Disable mock

  1. On the Mock tab, click Disable API Mock.

  2. In the confirmation dialog box, click OK.

    Important

    After you disable API mocking, the mock service becomes inaccessible. However, your mock configurations are retained and will be restored if you re-enable the feature.

Configure API management rules

  1. On the application API management page, click Configure API Management Rules.

  2. In the Configure API Management Rules panel, configure the following settings. The Description section at the top describes the platform’s default API definition rules. With the default rules, you do not need to perform extra actions during development. If you want to adjust the rules, update the definitions in your code and report them by scanning and merging models. For existing APIs, you can report them by adding annotations.

    Parameter

    Description

    Automatic rule version

    From the Automatic Rule Version drop-down list, select the target automatic rule version.

    API authentication

    Select the environment types where you want to enable API authentication. Supported types include development, testing, pre-release, and production.

    • If API authentication is disabled for the environment where the application is deployed, the API can be called directly from both inside and outside the cluster without authentication.

    • If API authentication is enabled for the environment where the application is deployed, calls from within the cluster do not require authentication, while calls from outside the cluster do.

    • You must redeploy the central application for the changes to take effect.

    1. Click OK.

Scan code for APIs

  1. On the application API management page, click API Scan. This button is in the upper-right corner of the page.

  2. In the Scan Code to Report API Information panel, click Scan Code Branch. In the Scan Code Branch panel, select a code branch from the drop-down list and click Submit. The panel shows existing scan records for code branches. The Scan Code Branch dialog box displays the Code Repository Address. Note that this scan overwrites existing API definitions with those found in the code.

    You can monitor the code scanning status in the Scan Code to Report API Information panel. If the scan succeeds, the API information is updated; if it fails, the reason for the failure is displayed. The panel displays a table with the Branch Name, Status, and Last Scanned time for each branch. Click Refresh to get the latest status.