第6章 Managing Apicurio Registry content using the REST API
Client applications can use Apicurio Registry REST API operations to manage schema and API artifacts in Apicurio Registry, for example, in a CI/CD pipeline deployed in production. The Core Registry API v3 provides operations for artifacts, versions, metadata, and rules stored in Apicurio Registry. For detailed information, see the Apicurio Registry REST API documentation.
This chapter shows examples of how to use the Core Registry API v3 to perform the following tasks:
- 「Managing schema and API artifacts using Apicurio Registry REST API commands」
- 「Managing schema and API artifact versions using Apicurio Registry REST API commands」
- 「Managing schema and API artifact references using Apicurio Registry REST API commands」
- 「Exporting and importing registry data using Apicurio Registry REST API commands」
Prerequisites
6.1. Managing schema and API artifacts using Apicurio Registry REST API commands リンクのコピーリンクがクリップボードにコピーされました!
This section shows a simple curl-based example of using the Core Registry API v3 to add and retrieve a simple schema artifact in Apicurio Registry.
Prerequisites
- Apicurio Registry is installed and running in your environment.
Procedure
Add an artifact to Apicurio Registry using the
/groups/{groupId}/artifactsoperation. The following examplecurlcommand adds a simple schema artifact for a share price application:$ 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" } } }'-
This example adds an Apache Avro schema artifact with an artifact ID of
share-price. If you do not specify a unique artifact ID, Apicurio Registry generates one automatically as a UUID. -
MY-REGISTRY-URLis the host name on which Apicurio Registry is deployed. For example:http://localhost:8080. -
This example specifies a group ID of
my-groupin the API path. If you do not specify a unique group ID, you must specify../groups/defaultin the API path.
-
This example adds an Apache Avro schema artifact with an artifact ID of
Verify that the response includes the expected JSON body to confirm that the artifact was added. For example:
{"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"}}-
No version was specified when adding the artifact, so the default version
1is created automatically. -
This was the second artifact added to Apicurio Registry, so the global ID and content ID have a value of
2.
-
No version was specified when adding the artifact, so the default version
Retrieve the artifact version content from Apicurio Registry using its artifact ID in the API path. In this example, the specified ID is
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"}]}