第 4 章 使用 REST API 管理 Apicurio Registry 内容


客户端应用程序可以使用 Apicurio Registry REST API 操作来管理 Apicurio Registry 中的 schema 和 API 工件,例如在生产环境中部署的 CI/CD 管道中。Core Registry API v3 为存储在 Apicurio Registry 中的工件、版本、元数据和规则提供操作。如需更多信息,请参阅 Apicurio Registry REST API 文档

本章演示了如何使用 Core Registry API v3 来执行以下任务:

本节展示了一个简单的基于 curl 的示例,它使用 Core Registry API v3 在 Apicurio Registry 中添加和删除简单的模式工件。

先决条件

  • Apicurio Registry 在您的环境中安装并运行。

流程

  1. 使用 /groups/{groupId}/artifacts 操作向 Apicurio Registry 添加工件。以下示例 curl 命令为共享价格应用程序添加一个简单的模式工件:

    $ curl -X POST MY-REGISTRY-URL/apis/registry/v3/groups/my-group/artifacts \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $ACCESS_TOKEN" \
      --data-raw '{
        "artifactId": "share-price",
        "artifactType": "AVRO",
        "firstVersion": {
            "content": {
                "content": "{\"type\":\"record\",\"name\":\" p\",\"namespace\":\"com.example\", \"fields\":[{\"name\":\"symbol\",\"type\":\"string\"},{\"name\":\"price\",\"type\":\"string\"}]}",
                "contentType": "application/json"
            }
        }
    }'
    Copy to Clipboard Toggle word wrap
    • 这个示例添加了一个 Apache Avro 模式工件,工件 ID 为 share-price。如果没有指定唯一的工件 ID,Apicurio Registry 会自动生成一个作为 UUID。
    • MY-REGISTRY-URL 是在其上部署 Apicurio Registry 的主机名。例如: my-cluster-service-registry-myproject.example.com
    • 本例在 API 路径中指定 my-group 的组 ID。如果没有指定唯一的组 ID,则必须在 API 路径中指定 ../groups/default
  2. 验证响应是否包含预期的 JSON 正文,以确认是否添加了构件。例如:

    {"artifact":{"owner":"","createdOn":"2024-09-26T17:24:21Z","modifiedBy":"","modifiedOn":"2024-09-26T17:24:21Z","artifactType":"AVRO","groupId":"my-group","artifactId":"share-price"},"version":{"version":"1","owner":"","createdOn":"2024-09-26T17:24:21Z","artifactType":"AVRO","globalId":2,"state":"ENABLED","groupId":"my-group","contentId":2,"artifactId":"share-price"}}
    Copy to Clipboard Toggle word wrap
    • 添加工件时没有指定 version,因此会自动创建默认版本 1
    • 这是添加到 Apicurio Registry 的第二个工件,因此全局 ID 和内容 ID 的值为 2
  3. 使用 API 路径中的工件 ID 从 Apicurio Registry 检索工件版本内容。在本例中,指定的 ID 是 share-price

    $ curl -H "Authorization: Bearer $ACCESS_TOKEN" \
     MY-REGISTRY-URL/apis/registry/v3/groups/my-group/artifacts/share-price/versions/1/content
     {"type":"record","name":"price","namespace":"com.example",
      "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat