API examples
These examples assume the Schema Registry is reachable at http://localhost:8081 and
the REST proxy at http://localhost:8082. Adjust the hosts to match your deployment.
Schema Registry
Register the first version of a schema under the subject test-key using an Avro schema:
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema": "{\"type\": \"record\", \"name\": \"Obj\", \"fields\":[{\"name\": \"age\", \"type\": \"int\"}]}"}' \
http://localhost:8081/subjects/test-key/versions
# Response:
# {"id":1}
Register a version of a schema using JSON Schema — set the schemaType property:
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schemaType": "JSON", "schema": "{\"type\": \"object\",\"properties\":{\"age\":{\"type\": \"number\"}},\"additionalProperties\":true}"}' \
http://localhost:8081/subjects/test-key-json-schema/versions
# Response:
# {"id":2}
List all subjects:
curl -X GET http://localhost:8081/subjects
# Response:
# ["test-key"]
List all versions of a given subject:
curl -X GET http://localhost:8081/subjects/test-key/versions
# Response:
# [1]
Fetch the schema whose global id is 1:
curl -X GET http://localhost:8081/schemas/ids/1
# Response:
# {"schema":"{\"fields\":[{\"name\":\"age\",\"type\":\"int\"}],\"name\":\"Obj\",\"type\":\"record\"}"}
Get version 1 of the schema:
curl -X GET http://localhost:8081/subjects/test-key/versions/1
Get the latest version of the schema under subject test-key:
curl -X GET http://localhost:8081/subjects/test-key/versions/latest
Delete version 10 of the schema registered under subject test-key (if it exists):
curl -X DELETE http://localhost:8081/subjects/test-key/versions/10
# Response:
# 10
Delete all versions of the schema registered under subject test-key:
curl -X DELETE http://localhost:8081/subjects/test-key
# Response:
# [1]
Test the compatibility of a schema with the latest schema under subject test-key:
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema": "{\"type\": \"int\"}"}' \
http://localhost:8081/compatibility/subjects/test-key/versions/latest
# Response:
# {"is_compatible":true}
If the subject's compatibility mode is transitive (BACKWARD_TRANSITIVE,
FORWARD_TRANSITIVE or FULL_TRANSITIVE), compatibility is checked not only against the
latest schema but also against all previous schemas.
Get the current global backwards compatibility setting:
curl -X GET http://localhost:8081/config
# Response:
# {"compatibilityLevel":"BACKWARD"}
Change compatibility requirements for all subjects where it is not otherwise defined:
curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"compatibility": "NONE"}' http://localhost:8081/config
# Response:
# {"compatibility":"NONE"}
Change compatibility requirement to FULL for the test-key subject:
curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"compatibility": "FULL"}' http://localhost:8081/config/test-key
# Response:
# {"compatibility":"FULL"}
REST Proxy
List topics:
curl "http://localhost:8082/topics"
Get info for one particular topic:
curl "http://localhost:8082/topics/my_topic"
Produce a message backed by the schema registry:
curl -H "Content-Type: application/vnd.kafka.avro.v2+json" -X POST -d \
'{"value_schema": "{\"namespace\": \"example.avro\", \"type\": \"record\", \"name\": \"simple\", \"fields\": [{\"name\": \"name\", \"type\": \"string\"}]}", "records": [{"value": {"name": "name0"}}]}' \
http://localhost:8082/topics/my_topic
Create a consumer with consumer group avro_consumers and instance my_consumer:
curl -X POST -H "Content-Type: application/vnd.kafka.v2+json" -H "Accept: application/vnd.kafka.v2+json" \
--data '{"name": "my_consumer", "format": "avro", "auto.offset.reset": "earliest"}' \
http://localhost:8082/consumers/avro_consumers
Subscribe to the topic:
curl -X POST -H "Content-Type: application/vnd.kafka.v2+json" --data '{"topics":["my_topic"]}' \
http://localhost:8082/consumers/avro_consumers/instances/my_consumer/subscription
Consume previously produced messages:
curl -X GET -H "Accept: application/vnd.kafka.avro.v2+json" \
http://localhost:8082/consumers/avro_consumers/instances/my_consumer/records?timeout=1000
Commit offsets for a topic partition:
curl -X POST -H "Content-Type: application/vnd.kafka.v2+json" --data '{}' \
http://localhost:8082/consumers/avro_consumers/instances/my_consumer/offsets
Delete the consumer:
curl -X DELETE -H "Accept: application/vnd.kafka.v2+json" \
http://localhost:8082/consumers/avro_consumers/instances/my_consumer