Chapter 4. Managing Apicurio Registry content using the REST API
Client applications can use Registry REST API operations to manage schema and API artifacts in Apicurio Registry, for example, in a CI/CD pipeline deployed in production. The Registry REST API provides create, read, update, and delete operations for artifacts, versions, metadata, and rules stored in the registry. For detailed information, see the Apicurio Registry REST API documentation.
This chapter describes the Apicurio Registry core REST API and shows how to use it to manage schema and API artifacts stored in the registry:
Prerequisites
4.1. Managing schema and API artifacts using Registry REST API commands Copy linkLink copied to clipboard!
This section shows a simple curl-based example of using the registry v2 core REST API to add and retrieve an Apache Avro schema artifact in the registry.
Prerequisites
- Apicurio Registry must be installed and running in your environment.
Procedure
Add an artifact to the registry using the
/groups/{group}/artifactsoperation. The following examplecurlcommand adds a simple artifact for a share price application:curl -X POST -H "Content-type: application/json; artifactType=AVRO" \ -H "X-Registry-ArtifactId: share-price" \ --data '{"type":"record","name":"price","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}' \ http://MY-REGISTRY-HOST/apis/registry/v2/groups/my-group/artifacts$ curl -X POST -H "Content-type: application/json; artifactType=AVRO" \ -H "X-Registry-ArtifactId: share-price" \1 --data '{"type":"record","name":"price","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}' \2 http://MY-REGISTRY-HOST/apis/registry/v2/groups/my-group/artifacts3 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- This example adds an 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. - 2
MY-REGISTRY-HOSTis the host name on which Apicurio Registry is deployed. For example:my-cluster-service-registry-myproject.example.com.- 3
- 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.
Verify that the response includes the expected JSON body to confirm that the artifact was added. For example:
{"createdBy":"","createdOn":"2021-04-16T09:07:51+0000","modifiedBy":"", "modifiedOn":"2021-04-16T09:07:51+0000","id":"share-price","version":"1", "type":"AVRO","globalId":2,"state":"ENABLED","groupId":"my-group","contentId":2}{"createdBy":"","createdOn":"2021-04-16T09:07:51+0000","modifiedBy":"", "modifiedOn":"2021-04-16T09:07:51+0000","id":"share-price","version":"1",1 "type":"AVRO","globalId":2,"state":"ENABLED","groupId":"my-group","contentId":2}2 Copy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve the artifact content from the registry using its artifact ID in the API path. In this example, the specified ID is
share-price:curl http://MY-REGISTRY-URL/apis/registry/v2/groups/my-group/artifacts/share-price \ {"type":"record","name":"price","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}$ curl http://MY-REGISTRY-URL/apis/registry/v2/groups/my-group/artifacts/share-price \ {"type":"record","name":"price","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2. Managing schema and API artifact versions using Registry REST API commands Copy linkLink copied to clipboard!
If you do not specify an artifact version when adding schema and API artifacts to Apicurio Registry using the v2 REST API, Apicurio Registry generates one automatically. The default version when creating a new artifact is 1.
Apicurio Registry also supports custom versioning where you can specify a version using the X-Registry-Version HTTP request header as a string. Specifying a custom version value overrides the default version normally assigned when creating or updating an artifact. You can then use this version value when executing REST API operations that require a version.
This section shows a simple curl-based example of using the registry v2 core REST API to add and retrieve a custom Apache Avro schema version in the registry. You can specify custom versions when using the REST API to add or update artifacts or to add artifact versions.
Prerequisites
- Apicurio Registry must be installed and running in your environment.
Procedure
Add an artifact version in the registry using the
/groups/{group}/artifactsoperation. The following examplecurlcommand adds a simple artifact for a share price application:curl -X POST -H "Content-type: application/json; artifactType=AVRO" \ -H "X-Registry-ArtifactId: my-share-price" -H "X-Registry-Version: 1.1.1" \ --data '{"type":"record","name":" p","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}' \ http://MY-REGISTRY-HOST/apis/registry/v2/groups/my-group/artifacts$ curl -X POST -H "Content-type: application/json; artifactType=AVRO" \ -H "X-Registry-ArtifactId: my-share-price" -H "X-Registry-Version: 1.1.1" \1 --data '{"type":"record","name":" p","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}' \2 http://MY-REGISTRY-HOST/apis/registry/v2/groups/my-group/artifacts3 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- This example adds an Avro schema artifact with an artifact ID of
my-share-priceand version of1.1.1. If you do not specify a version, Apicurio Registry automatically generates a default version of1. - 2
MY-REGISTRY-HOSTis the host name on which Apicurio Registry is deployed. For example:my-cluster-service-registry-myproject.example.com.- 3
- 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.
Verify that the response includes the expected JSON body to confirm that the custom artifact version was added. For example:
{"createdBy":"","createdOn":"2021-04-16T10:51:43+0000","modifiedBy":"", "modifiedOn":"2021-04-16T10:51:43+0000","id":"my-share-price","version":"1.1.1", "type":"AVRO","globalId":3,"state":"ENABLED","groupId":"my-group","contentId":3}{"createdBy":"","createdOn":"2021-04-16T10:51:43+0000","modifiedBy":"", "modifiedOn":"2021-04-16T10:51:43+0000","id":"my-share-price","version":"1.1.1",1 "type":"AVRO","globalId":3,"state":"ENABLED","groupId":"my-group","contentId":3}2 Copy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve the artifact content from the registry using its artifact ID and version in the API path. In this example, the specified ID is
my-share-priceand the version is1.1.1:curl http://MY-REGISTRY-URL/apis/registry/v2/groups/my-group/artifacts/my-share-price/versions/1.1.1 \ {"type":"record","name":"price","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}$ curl http://MY-REGISTRY-URL/apis/registry/v2/groups/my-group/artifacts/my-share-price/versions/1.1.1 \ {"type":"record","name":"price","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3. Exporting and importing registry content using Registry REST API commands Copy linkLink copied to clipboard!
This section shows a simple curl-based example of using the registry v2 core REST API to export and import existing registry data in .zip format from one Apicurio Registry instance to another. For example, this is useful when migrating or upgrading from one Apicurio Registry v2.x instance to another.
Prerequisites
- Apicurio Registry must be installed and running in your environment.
Procedure
Export the registry data from your existing source Apicurio Registry instance:
curl http://MY-REGISTRY-HOST/apis/registry/v2/admin/export \ --output my-registry-data.zip
$ curl http://MY-REGISTRY-HOST/apis/registry/v2/admin/export \ --output my-registry-data.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow MY-REGISTRY-HOSTis the host name on which the source Apicurio Registry is deployed. For example:my-cluster-source-registry-myproject.example.com.Import the registry data into your target Apicurio Registry instance:
curl -X POST "http://MY-REGISTRY-HOST/apis/registry/v2/admin/import" \ -H "Content-Type: application/zip" --data-binary @my-registry-data.zip
$ curl -X POST "http://MY-REGISTRY-HOST/apis/registry/v2/admin/import" \ -H "Content-Type: application/zip" --data-binary @my-registry-data.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow MY-REGISTRY-HOSTis the host name on which the target Apicurio Registry is deployed. For example:my-cluster-target-registry-myproject.example.com.