Expand description
§Schema registry API
Provide a REST API to call with a schema registry.
§Examples
List subjects
use reqwest::Url;
use schema_registry_api::SchemaRegistry;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a `SchemaRegistry`
let base_url = Url::parse("http://localhost:8081")?;
let sr = SchemaRegistry::build_default(base_url)?;
// List subjects
let subjects = sr.subject().list(None, None).await?;
if subjects.is_empty() {
println!("No subject found");
}
for subject in &subjects {
println!("Found subject '{subject}'");
}
Ok(())
}
Register a schema
use reqwest::Url;
use schema_registry_api::{RegisterSchema, SchemaRegistry};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a `SchemaRegistry`
let base_url = Url::parse("http://localhost:8081")?;
let sr = SchemaRegistry::build_default(base_url)?;
// Create a subject
let subject = "a-topic-value".parse()?;
// Create the `RegisterSchema`
let schema = RegisterSchema {
schema: include_str!("../tests/assets/a_record.avsc").to_string(),
..Default::default()
};
// Register the schema for the subject
let registered_schema = sr.subject().new_version(&subject, &schema, None).await?;
// Get the schema id
let schema_id = registered_schema.id;
println!("The schema #{schema_id} is registered for subject '{subject}'");
Ok(())
}
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Structs§
- ApiError
- An API error
- Compatibility
- The compatibility
- Compatibility
Client - The compatibility client
- Compatibility
Result - Compatibility result
- Config
Client - The configuration client
- GetCompatibility
- The compatibility get result
- Mode
- The mode wrapper
- Mode
Client - The subject client
- Register
Schema - Register a schema
- Registered
Schema - Registered schema result
- Schema
- A Schema payload
- Schema
Client - The subject client
- Schema
Id - The schema id
- Schema
IdError - An Schema id error
- Schema
Reference - A schema reference
- Schema
Registry - A schema registry client
- Schema
Version Error - An Schema version error
- Subject
- A subject
- Subject
Client - The subject client
- Subject
Name - A subject name
- Subject
Version - A subject an associated version
Enums§
- Compatibility
Level - Compatibility level
- Resource
Mode - The resource mode
- Schema
Registry Error - A schema registry error
- Schema
Type - A Schema type
- Schema
Version - The schema version
- Subject
Name Error - An subject error