pub struct Client { /* private fields */ }Expand description
Client for ip-allocator-webserver
Version: 0.2.0
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(baseurl: &str) -> Self
pub fn new(baseurl: &str) -> Self
Create a new client.
baseurl is the base URL provided to the internal
reqwest::Client, and should include a scheme and hostname,
as well as port and a path stem if applicable.
Examples found in repository?
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Create a new client
6 let client = Client::new("http://localhost:8000");
7
8 // Borrow an item from the freelist
9 println!("🔄 Borrowing an item...");
10 // Pass None for immediate return, or Some(seconds) to wait for availability
11 // Example: client.handlers_ip_borrow(Some(30)).await? // Wait up to 30 seconds
12 let borrow_result = client.handlers_ip_borrow(None).await?;
13 println!("✅ Borrowed item: {:?}", borrow_result.item);
14 println!("🎟️ Borrow token: {}", borrow_result.borrow_token);
15
16 // Return the borrowed item to the freelist
17 println!("\n🔄 Returning the item...");
18 let return_input = ip_allocator_client::types::ReturnInput {
19 item: borrow_result.item.clone(),
20 borrow_token: borrow_result.borrow_token.clone(),
21 };
22 let return_result = client.handlers_ip_return_item(&return_input).await?;
23 println!("✅ Return operation initiated: {:?}", return_result);
24
25 // Check operation status
26 println!("\n🔄 Checking operation status...");
27 let status = client
28 .handlers_ip_get_operation_status(&return_result.operation_id)
29 .await?;
30 println!("✅ Operation status: {:?}", status);
31
32 Ok(())
33}Sourcepub fn new_with_client(baseurl: &str, client: Client) -> Self
pub fn new_with_client(baseurl: &str, client: Client) -> Self
Construct a new client with an existing reqwest::Client,
allowing more control over its configuration.
baseurl is the base URL provided to the internal
reqwest::Client, and should include a scheme and hostname,
as well as port and a path stem if applicable.
Sourcepub fn api_version(&self) -> &'static str
pub fn api_version(&self) -> &'static str
Get the version of this API.
This string is pulled directly from the source OpenAPI document and may be in any format the API selects.
Source§impl Client
impl Client
Sourcepub async fn handlers_ip_borrow<'a>(
&'a self,
wait: Option<u64>,
) -> Result<ResponseValue<BorrowOutput>, Error<()>>
pub async fn handlers_ip_borrow<'a>( &'a self, wait: Option<u64>, ) -> Result<ResponseValue<BorrowOutput>, Error<()>>
Borrow an item from the freelist
Returns an item along with a borrow_token that must be provided when returning the item. Optional query parameter wait specifies the maximum number of seconds to wait for an item to become available. If not specified, returns immediately. If specified, the request will block until an item becomes available or the timeout is reached.
Sends a GET request to /borrow
Examples found in repository?
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Create a new client
6 let client = Client::new("http://localhost:8000");
7
8 // Borrow an item from the freelist
9 println!("🔄 Borrowing an item...");
10 // Pass None for immediate return, or Some(seconds) to wait for availability
11 // Example: client.handlers_ip_borrow(Some(30)).await? // Wait up to 30 seconds
12 let borrow_result = client.handlers_ip_borrow(None).await?;
13 println!("✅ Borrowed item: {:?}", borrow_result.item);
14 println!("🎟️ Borrow token: {}", borrow_result.borrow_token);
15
16 // Return the borrowed item to the freelist
17 println!("\n🔄 Returning the item...");
18 let return_input = ip_allocator_client::types::ReturnInput {
19 item: borrow_result.item.clone(),
20 borrow_token: borrow_result.borrow_token.clone(),
21 };
22 let return_result = client.handlers_ip_return_item(&return_input).await?;
23 println!("✅ Return operation initiated: {:?}", return_result);
24
25 // Check operation status
26 println!("\n🔄 Checking operation status...");
27 let status = client
28 .handlers_ip_get_operation_status(&return_result.operation_id)
29 .await?;
30 println!("✅ Operation status: {:?}", status);
31
32 Ok(())
33}Sourcepub async fn handlers_ip_return_item<'a>(
&'a self,
body: &'a ReturnInput,
) -> Result<ResponseValue<OperationRef>, Error<()>>
pub async fn handlers_ip_return_item<'a>( &'a self, body: &'a ReturnInput, ) -> Result<ResponseValue<OperationRef>, Error<()>>
Return an item to the freelist
Requires the borrow_token that was provided when the item was borrowed. This prevents accidentally returning an item currently borrowed by someone else.
Sends a POST request to /return
Examples found in repository?
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Create a new client
6 let client = Client::new("http://localhost:8000");
7
8 // Borrow an item from the freelist
9 println!("🔄 Borrowing an item...");
10 // Pass None for immediate return, or Some(seconds) to wait for availability
11 // Example: client.handlers_ip_borrow(Some(30)).await? // Wait up to 30 seconds
12 let borrow_result = client.handlers_ip_borrow(None).await?;
13 println!("✅ Borrowed item: {:?}", borrow_result.item);
14 println!("🎟️ Borrow token: {}", borrow_result.borrow_token);
15
16 // Return the borrowed item to the freelist
17 println!("\n🔄 Returning the item...");
18 let return_input = ip_allocator_client::types::ReturnInput {
19 item: borrow_result.item.clone(),
20 borrow_token: borrow_result.borrow_token.clone(),
21 };
22 let return_result = client.handlers_ip_return_item(&return_input).await?;
23 println!("✅ Return operation initiated: {:?}", return_result);
24
25 // Check operation status
26 println!("\n🔄 Checking operation status...");
27 let status = client
28 .handlers_ip_get_operation_status(&return_result.operation_id)
29 .await?;
30 println!("✅ Operation status: {:?}", status);
31
32 Ok(())
33}Sourcepub async fn handlers_ip_get_operation_status<'a>(
&'a self,
id: &'a str,
) -> Result<ResponseValue<OperationStatusOutput>, Error<()>>
pub async fn handlers_ip_get_operation_status<'a>( &'a self, id: &'a str, ) -> Result<ResponseValue<OperationStatusOutput>, Error<()>>
Poll the status of an async operation
Sends a GET request to /operations/{id}
Examples found in repository?
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Create a new client
6 let client = Client::new("http://localhost:8000");
7
8 // Borrow an item from the freelist
9 println!("🔄 Borrowing an item...");
10 // Pass None for immediate return, or Some(seconds) to wait for availability
11 // Example: client.handlers_ip_borrow(Some(30)).await? // Wait up to 30 seconds
12 let borrow_result = client.handlers_ip_borrow(None).await?;
13 println!("✅ Borrowed item: {:?}", borrow_result.item);
14 println!("🎟️ Borrow token: {}", borrow_result.borrow_token);
15
16 // Return the borrowed item to the freelist
17 println!("\n🔄 Returning the item...");
18 let return_input = ip_allocator_client::types::ReturnInput {
19 item: borrow_result.item.clone(),
20 borrow_token: borrow_result.borrow_token.clone(),
21 };
22 let return_result = client.handlers_ip_return_item(&return_input).await?;
23 println!("✅ Return operation initiated: {:?}", return_result);
24
25 // Check operation status
26 println!("\n🔄 Checking operation status...");
27 let status = client
28 .handlers_ip_get_operation_status(&return_result.operation_id)
29 .await?;
30 println!("✅ Operation status: {:?}", status);
31
32 Ok(())
33}