The Schema Registry support a REST API for finding out information about the schemas within it. Here’s a quick cheatsheat with REST calls that I often use.
Note
|
If you’re connecting to Schema Registry on Confluent Cloud then you need to specify your Schema Registry API key and secret as authentication in the HTTP request:
|
-
$ curl -s "http://localhost:8081/subjects/" ["COMP_WATCH_BY_EMP_ID_T-value"]⏎
-
$ curl -s "http://localhost:8081/schemas/ids/1" {"schema":"{\"type\":\"record\",\"name\":\"KsqlDataSourceSchema\",\"namespace\":\"io.confluent.ksql.avro_schemas\",\"fields\":[{\"name\":\"EMP_ID\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"EMP_NAME\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"EMP_KEY\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"MACADDR\",\"type\":[\"null\",\"string\"],\"default\":null}]}"}⏎
-
List latest schema for given subject
$ curl -s "http://localhost:8081/subjects/COMP_WATCH_BY_EMP_ID_T-value/versions/latest"|jq '.' { "subject": "COMP_WATCH_BY_EMP_ID_T-value", "version": 1, "id": 1, "schema": "{\"type\":\"record\",\"name\":\"KsqlDataSourceSchema\",\"namespace\":\"io.confluent.ksql.avro_schemas\",\"fields\":[{\"name\":\"EMP_ID\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"EMP_NAME\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"EMP_KEY\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"MACADDR\",\"type\":[\"null\",\"string\"],\"default\":null}]}" }
-
List schema for given subject and version
$ curl -s "http://localhost:8081/subjects/COMP_WATCH_BY_EMP_ID_T-value/versions/1"|jq '.' { "subject": "COMP_WATCH_BY_EMP_ID_T-value", "version": 1, "id": 1, "schema": "{\"type\":\"record\",\"name\":\"KsqlDataSourceSchema\",\"namespace\":\"io.confluent.ksql.avro_schemas\",\"fields\":[{\"name\":\"EMP_ID\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"EMP_NAME\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"EMP_KEY\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"MACADDR\",\"type\":[\"null\",\"string\"],\"default\":null}]}" }
-
List versions for given subject
$ curl -s "http://localhost:8081/subjects/COMP_WATCH_BY_EMP_ID_T-value/versions/" [1]⏎
-
Use
jq
to reformat the schema JSON:$ curl -s "http://localhost:8081/subjects/COMP_WATCH_BY_EMP_ID_T-value/versions/1"|jq '.schema|fromjson' { "type": "record", "name": "KsqlDataSourceSchema", "namespace": "io.confluent.ksql.avro_schemas", "fields": [ { "name": "EMP_ID", "type": [ "null", "string" ], "default": null }, { "name": "EMP_NAME", "type": [ "null", "string" ], "default": null }, { "name": "EMP_KEY", "type": [ "null", "string" ], "default": null }, { "name": "MACADDR", "type": [ "null", "string" ], "default": null } ] }
-
Use
jq
to show schema for columns matching a given name pattern$ curl -s "http://localhost:8081/subjects/oracle-04-NUM_TEST-value/versions/latest"|jq '.schema|fromjson.fields[] | select (.name | contains("AMOUNT"))' { "name": "AMOUNT_01", "type": [ "null", "double" ], "default": null } { "name": "AMOUNT_02", "type": [ "null", "double" ], "default": null } { "name": "AMOUNT_03", "type": [ "null", "int" ], "default": null } { "name": "AMOUNT_04", "type": [ "null", "double" ], "default": null } { "name": "AMOUNT_05", "type": [ "null", "double" ], "default": null } { "name": "AMOUNT_06", "type": [ "null", "double" ], "default": null } { "name": "AMOUNT_07", "type": [ "null", "double" ], "default": null }
-
Register a new schema
echo '{ "type": "record", "name": "myrecord", "fields": [ { "name": "tags", "type": { "type": "map", "values": "string" } }, { "name": "AVG_NOISE_FLOOR_DBM", "type": [ "null", "double" ], "default": null }, { "name": "OFDM_ANI_LEVEL_ADJUSTED", "type": [ "null", "int" ], "default": null } ] }' | \ jq '. | {schema: tojson}' | \ curl -X POST http://localhost:8081/subjects/sonos_metrics_avro_01-value/versions \ -H "Content-Type:application/json" \ -d @-
-
Register a new schema from
.avsc
jq '. | {schema: tojson}' /tmp/example.avsc | \ curl -X POST http://localhost:8081/subjects/my_schema_01-value/versions \ -H "Content-Type:application/json" \ -d @-