包装 API

Blockchain App Builder 的增强版本可以为 API Gateway 生成包装 API,这些 API 支持每个链代码方法的专用端点。

包装 API 是基于 Oracle Blockchain Platform 端点的抽象层。包装 API 支持配置通用参数和特定于 API 的端点名称,这可以简化使用和清晰度。

Oracle Blockchain Platform 的基本版本中,API 端点需要参数,包括链代码名称、超时和同步值、参数(包括方法名称)、通道名称和实例 URL。这些参数必须在每次调用时传递。由于这些参数中的大多数对所有方法都通用,因此可以使用包装 API 功能为每个方法创建一个端点,然后仅使用方法参数调用该端点。您可以为每个方法使用定制端点名称,而不使用公用端点(事务处理或查询)。Oracle Blockchain Platform 中的 API 端点使用 POST 请求,而包装 API 同时支持 POST 和 GET 请求。您还可以使用 API 网关验证机制,通过包装 API 添加额外的验证层。

以下示例显示了 Oracle Blockchain Platform 中的 createAccount 方法 API。

端点:https://<blockchain_instance>:7443/restproxy/api/v2/channels/<channelName>/transactions

{
    "chaincode": "{{bc-chaincode-name}}",
    "args": [
        "createAccount",
        "{{bc-org-id}}",
        "{{bc-user-id}}",
        "fungible",
        "{\"max_daily_amount\":10000,\"max_daily_transactions\":100}"
    ],
    "timeout": {{bc-timeout}},
    "sync": {{bc-sync}}
}

如果配置包装 API,则可以进行与以下示例中所示相同的方法调用。

端点:https://<gateway-hostname>/<deployment-path-prefix>/<route-path>

{
    "orgId": "{{bc-org-id}}",
    "userId": "user1",
    "tokenType": "fungible",
    "dailyLimits": "{\"max_daily_amount\":10000,\"max_daily_transactions\":100}",
}