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

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
  1. Add an artifact to Apicurio Registry using the /groups/{groupId}/artifacts operation. The following example curl command 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-URL is the host name on which Apicurio Registry is deployed. For example: http://localhost:8080.

    • This example specifies a group ID of my-group in the API path. If you do not specify a unique group ID, you must specify ../groups/default in the API path.

  2. 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 1 is created automatically.

    • This was the second artifact added to Apicurio Registry, so the global ID and content ID have a value of 2.

  3. 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"}]}
Additional resources

Managing schema and API artifact versions using Apicurio Registry REST API commands

If you do not specify an artifact version number when adding schema and API artifacts using the Core Registry API v3, Apicurio Registry generates a version number automatically. The default version when creating a new artifact is 1.

Apicurio Registry also supports custom versioning where you can specify a version number when creating the artifact or artifact version. Specifying a custom version value overrides the default version normally assigned when creating an artifact or artifact version. You can then use this version value when executing REST API operations that require a version number.

This section shows a simple curl-based example of using the Core Registry API v3 to add and retrieve a custom Apache Avro schema version in Apicurio Registry. You can specify custom version numbers to create artifacts, or to add artifact versions.

Prerequisites
  • Apicurio Registry is installed and running in your environment.

Procedure
  1. Add an artifact version in the registry using the /groups/{groupId}/artifacts operation. The following example curl command adds a simple 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": "my-share-price",
        "artifactType": "AVRO",
        "firstVersion": {
            "version": "1.1.1",
            "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 Avro schema artifact with an artifact ID of my-share-price and version of 1.1.1. If you do not specify a version, Apicurio Registry automatically generates a default version of 1.

    • MY-REGISTRY-URL is the host name on which Apicurio Registry is deployed. For example: http://localhost:8080.

    • This example specifies a group ID of my-group in the API path. If you do not specify a unique group ID, you must specify ../groups/default in the API path.

  2. Verify that the response includes the expected JSON body to confirm that the custom artifact version was added. For example:

    {"artifact":{"owner":"","createdOn":"2024-09-26T17:06:21Z","modifiedBy":"","modifiedOn":"2024-09-26T17:06:21Z","artifactType":"AVRO","groupId":"my-group","artifactId":"my-share-price"},"version":{"version":"1.1.1","owner":"","createdOn":"2024-09-26T17:06:21Z","artifactType":"AVRO","globalId":4,"state":"ENABLED","groupId":"my-group","contentId":4,"artifactId":"my-share-price"}}
    • A custom version of 1.1.1 was specified when adding the artifact.

    • This was the fourth artifact added to the registry, so the global ID and content ID have a value of 4.

  3. 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-price and the version is 1.1.1:

    $ curl -H "Authorization: Bearer $ACCESS_TOKEN" \
        MY-REGISTRY-URL/apis/registry/v3/groups/my-group/artifacts/my-share-price/versions/1.1.1/content
    {"type":"record","name":"price","namespace":"com.example",
      "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}
Additional resources

Managing schema and API artifact references using Apicurio Registry REST API commands

Some Apicurio Registry artifact types can include artifact references from one artifact file to another. You can create efficiencies by defining reusable schema or API artifacts, and then referencing them from multiple locations in artifact references.

The following artifact types support artifact references:

  • Apache Avro

  • Google Protobuf

  • JSON Schema

  • OpenAPI

  • AsyncAPI

This section shows a simple curl-based example of using the Core Registry API v3 to add and retrieve an artifact reference to a simple Avro schema artifact in Apicurio Registry.

This example first creates a schema artifact named ItemId:

ItemId schema
{
    "namespace":"com.example.common",
    "name":"ItemId",
    "type":"record",
    "fields":[
        {
            "name":"id",
            "type":"int"
        }
    ]
}

This example then creates a schema artifact named Item, which includes a reference to the nested ItemId artifact.

Item schema with nested ItemId schema
{
    "namespace":"com.example.common",
    "name":"Item",
    "type":"record",
    "fields":[
        {
            "name":"itemId",
            "type":"com.example.common.ItemId"
        }
    ]
}
Prerequisites
  • Apicurio Registry is installed and running in your environment.

Procedure
  1. Add the ItemId schema artifact that you want to create the nested artifact reference to using the /groups/{groupId}/artifacts operation:

    $ curl -X POST MY-REGISTRY-URL/apis/registry/v3/groups/my-group/artifacts \
       -H "Content-Type: application/json" \
       -H "Authorization: Bearer $ACCESS_TOKEN" \
       --data '{"artifactId":"ItemId","artifactType":"AVRO","firstVersion":{"version":"1.0.0","content":{"content":"{\"namespace\":\"com.example.common\",\"name\":\"ItemId\",\"type\":\"record\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"}]}","contentType":"application/json"}}}'
    • This example adds an Avro schema artifact with an artifact ID of ItemId. If you do not specify a unique artifact ID, Apicurio Registry generates one automatically as a UUID.

    • MY-REGISTRY-URL is the host name on which Apicurio Registry is deployed. For example: http://localhost:8080.

    • This example specifies a group ID of my-group in the API path. If you do not specify a unique group ID, you must specify ../groups/default in the API path.

  2. Verify that the response includes the expected JSON body to confirm that the artifact was added. For example:

    {"artifact":{"owner":"","createdOn":"2024-09-26T16:27:38Z","modifiedBy":"","modifiedOn":"2024-09-26T16:27:38Z","artifactType":"AVRO","groupId":"my-group","artifactId":"ItemId"},"version":{"version":"1.0.0","owner":"","createdOn":"2024-09-26T16:27:38Z","artifactType":"AVRO","globalId":2,"state":"ENABLED","groupId":"my-group","contentId":2,"artifactId":"ItemId"}}
  3. Add the Item schema artifact that includes the artifact reference to the ItemId schema using the /groups/{groupId}/artifacts operation:

    $ 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": "Item",
    	"artifactType": "AVRO",
    	"firstVersion": {
    		"version": "1.0.0",
    		"content": {
    			"content": "{\"namespace\":\"com.example.common\",\"name\":\"Item\",\"type\":\"record\",\"fields\":[{\"name\":\"itemId\",\"type\":\"com.example.common.ItemId\"}]}",
    			"contentType": "application/json",
    			"references": [
    				{
    					"name": "com.example.common.ItemId",
    					"groupId": "my-group",
    					"artifactId": "ItemId",
    					"version": "1.0.0"
    				}
    			]
    		}
    	}
    }'
    • For artifact references, you must specify the custom content type of application/create.extended+json, which extends the application/json content type.

  4. Verify that the response includes the expected JSON body to confirm that the artifact was created with the reference. For example:

    {"artifact":{"owner":"","createdOn":"2024-09-26T16:28:45Z","modifiedBy":"","modifiedOn":"2024-09-26T16:28:45Z","artifactType":"AVRO","groupId":"my-group","artifactId":"Item"},"version":{"version":"1.0.0","owner":"","createdOn":"2024-09-26T16:28:45Z","artifactType":"AVRO","globalId":3,"state":"ENABLED","groupId":"my-group","contentId":3,"artifactId":"Item"}}
  5. Retrieve the artifact reference from Apicurio Registry by specifying the coordinates of the artifact that includes the reference:

    $ curl -H "Authorization: Bearer $ACCESS_TOKEN" MY-REGISTRY-URL/apis/registry/v3/groups/my-group/artifacts/Item/versions/1.0.0/references
  6. Verify that the response includes the expected JSON body for this artifact reference. For example:

    [{"groupId":"my-group","artifactId":"ItemId","version":"1.0.0","name":"com.example.common.ItemId"}]

Dereference

There are some situations where having an artifact’s content with the referenced content inlined might be helpful. For those situations, the Core Registry API v3 supports the references parameter in certain operations.

This support is currently implemented for Avro, JSON Schema, Protobuf, OpenAPI and AsyncAPI when the parameter is present in a particular API operation. The parameter is not supported in other schema types.

  1. Retrieve the dereferenced (inlined) schema content:

    $ curl -H "Authorization: Bearer $ACCESS_TOKEN" MY-REGISTRY-URL/apis/registry/v3/groups/my-group/artifacts/Item/versions/1.0.0/content?references=DEREFERENCE
  2. Verify that the response includes the expected JSON body for this artifact content with the references inlined. For example:

    {"type":"record","name":"Item","namespace":"com.example.common","fields":[{"name":"itemId","type":{"type":"record","name":"ItemId","fields":[{"name":"id","type":"int"}]}}]}

This support is currently implemented only for Avro, Protobuf, OpenAPI, AsyncAPI, and JSON Schema artifacts when the dereference parameter is specified in the API operation. This parameter is not supported for any other artifact types.

For Protobuf artifacts, dereferencing content is supported only when all the schemas belong to the same package.
Circular dependencies are allowed by some artifact types (e.g. JSON Schema) but are not supported by Apicurio Registry.
Additional resources

Exporting and importing registry data using Apicurio Registry REST API commands

As an administrator, you can use the Core Registry API v3 to export data from one Apicurio Registry instance and import into another Apicurio Registry instance, so you can migrate data between different instances.

This section shows a simple curl-based example of using the Core Registry API v3 to export and import existing data in .zip format from one Apicurio Registry instance to another. All the artifact data contained in the Apicurio Registry instance is exported in the .zip file.

Prerequisites
  • Apicurio Registry is installed and running in your environment.

  • Apicurio Registry instances have been created:

    • The source instance that you want to export data from contains at least one schema or API artifact.

    • The target instance that you want to import data into is empty to preserve unique IDs.

Procedure
  1. Export the Apicurio Registry data from your existing source Apicurio Registry instance:

    $ curl MY-REGISTRY-URL/apis/registry/v3/admin/export \
      -H "Authorization: Bearer $ACCESS_TOKEN" \
      --output my-registry-data.zip

    MY-REGISTRY-URL is the host name on which the source Apicurio Registry is deployed. For example: http://my-source-registry:8080.

  2. Import the registry data into your target Apicurio Registry instance:

    $ curl -X POST "MY-REGISTRY-URL/apis/registry/v3/admin/import" \
      -H "Content-Type: application/zip" -H "Authorization: Bearer $ACCESS_TOKEN" \
      --data-binary @my-registry-data.zip

    MY-REGISTRY-URL is the host name on which the target Apicurio Registry is deployed. For example: http://my-target-registry:8080.

Additional resources