Skip to main content

Rust

You can use the progenitor crate to generate a Rust client from the OpenAPI specification of the Rest API. This will allow you to have type-safe access to the API endpoints and data structures.

Add the required dependency to your Cargo.toml:

[dependencies]
progenitor = "0.10"

Run the following command to generate the Rust client from the OpenAPI specification:

progenitor generate https://api.kimzee.com/docs/swagger.json -o ./client

Here is an example of how to use the generated client to make a request to the Rest API:

/src/client.rs
use client::{Client, AuthenticatedClient};
use client::api::campaign::{get_campaign, submit_campaign_entry};
use client::models::SubmitCampaignEntryRequest;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the client
let client = Client::new("https://api.kimzee.com/api/v1/");

// Authenticate the client
let authenticated_client = AuthenticatedClient::new(
"https://api.kimzee.com/api/v1/",
"YOUR_API_KEY",
);

// Fetch all campaigns accessible with the provided API key
let campaigns = get_campaign(&authenticated_client).await?;
let example_campaign = campaigns.iter().find(|c| c.name == "Campaign Test");

let Some(campaign) = example_campaign else {
println!("No matching campaign found.");
return Ok(());
};

// Submit a new entry to the campaign with the provided resourceId and body
let entry_request = SubmitCampaignEntryRequest {
data: serde_json::json!({
"email": "test@example.com",
"name": "Test User",
"birthday": "1997-10-17",
"company": "My Company",
"technology": "Rust"
}),
};

let submit_response = submit_campaign_entry(
&authenticated_client,
&campaign.resource.id,
&entry_request,
).await?;

println!("Entry submitted successfully: {:?}", submit_response);
Ok(())
}