Deboa

A very simple and straightforward HTTP client written in Rust.

View the Project on GitHub ararog/deboa

Vamo Macros

Procedural macros for the Vamo crate, enabling seamless integration with the Deboa HTTP client.

Features

Installation

[dependencies]
vamo-macros = "0.1.0"

Usage

Basic Resource

use serde::{Deserialize, Serialize};
use vamo_macros::Resource;

#[derive(Debug, Serialize, Deserialize, Resource)]
#[resource(path = "/users")]
struct User {
    id: Option<u64>,
    name: String,
    email: String,
}

Custom Endpoints

#[derive(Debug, Serialize, Deserialize, Resource)]
#[resource(path = "/articles")]
struct Article {
    id: Option<u64>,
    title: String,
    content: String,
    published: bool,
    
    #[resource(skip)]
    metadata: Option<serde_json::Value>,
}

// Custom implementation for the Article resource
impl Article {
    // Custom method to publish an article
    pub async fn publish(&mut self, client: &vamo::Client) -> Result<Self, vamo::Error> {
        self.published = true;
        self.update(client).await
    }
    
    // Custom endpoint to get published articles
    pub async fn published(client: &vamo::Client) -> Result<Vec<Self>, vamo::Error> {
        Self::list_with_params(client, &[("published", "true")]).await
    }
}

Field Attributes

#[derive(Debug, Serialize, Deserialize, Resource)]
#[resource(path = "/products")]
struct Product {
    id: Option<u64>,
    name: String,
    
    #[resource(readonly)]
    created_at: Option<String>,
    
    #[resource(skip_deserialize)]
    temporary_data: Option<String>,
    
    #[resource(skip_serialize)]
    secret_token: Option<String>,
}

Nested Resources

#[derive(Debug, Serialize, Deserialize, Resource)]
#[resource(path = "/users/{user_id}/posts")]
struct UserPost {
    id: Option<u64>,
    user_id: u64,
    title: String,
    content: String,
}

// Usage
let posts = UserPost::list_with_params(
    &client, 
    &[("user_id", "1")]
).await?;

Attribute Reference

Struct Attributes

Field Attributes

Custom Serialization

use serde::{Serialize, Deserialize};
use std::str::FromStr;

#[derive(Debug, Resource)]
#[resource(path = "/custom")]
struct CustomResource {
    id: Option<u64>,
    
    #[serde(serialize_with = "serialize_custom", deserialize_with = "deserialize_custom")]
    data: CustomType,
}

#[derive(Debug)]
struct CustomType {
    value: String,
}

fn serialize_custom<S>(value: &CustomType, serializer: S) -> Result<S::Ok, S::Error>
where
    S: serde::Serializer,
{
    serializer.serialize_str(&value.value)
}

fn deserialize_custom<'de, D>(deserializer: D) -> Result<CustomType, D::Error>
where
    D: serde::Deserializer<'de>,
{
    let s = String::deserialize(deserializer)?;
    Ok(CustomType { value: s })
}

Error Handling

use vamo::Error as VamoError;

match article.update(&client).await {
    Ok(updated) => println!("Updated: {:?}", updated),
    Err(VamoError::Validation(errors)) => {
        eprintln!("Validation errors: {:?}", errors);
    }
    Err(e) => eprintln!("Error: {}", e),
}

Features

Examples

See the examples directory for more usage examples.

API Reference

For detailed API documentation, see the docs.rs page.