A Rust WebAssembly plugin for the Noorle platform that provides real-time exchange rates and currency conversion capabilities.
- Exchange Rates: Get current exchange rates for any base currency with optional filtering
- Currency Conversion: Convert amounts between different currencies using live rates
- Currency List: Retrieve all supported currencies with their full names
- Robust Error Handling: Uses
result<string, string>for type-safe error handling - Fallback Support: Automatic fallback to secondary API if primary fails
- Fast & Efficient: Built with Rust for optimal WASM performance
This exchange rate plugin demonstrates essential patterns for building financial/data-driven Noorle plugins:
- Multiple API Endpoints: Shows how to implement fallback strategies for reliability
- Data Caching: Efficient handling of rate data to minimize API calls
- Precision Handling: Working with floating-point currency calculations
- Error Recovery: Graceful fallback when primary data sources fail
WebAssembly Component Model with WASI 0.2 provides secure, portable sandboxing with standardized system interfaces.
Key Design Patterns:
- Fallback API Strategy: Primary and secondary endpoints for high availability
- Free API Usage: No API keys required - uses open currency data sources
- Stateless Operations: Each function call is independent for scalability
# Build the plugin (creates WASM component)
noorle plugin build
# Deploy to Noorle platform
noorle plugin deploy# Test exchange rate retrieval
wasmtime run --wasi http \
--invoke 'get-exchange-rates("usd", "eur,gbp,jpy")' dist/plugin.wasm
# Test currency conversion
wasmtime run --wasi http \
--invoke 'convert-currency("usd", "eur", 100.0)' dist/plugin.wasm
# Test listing all currencies
wasmtime run --wasi http \
--invoke 'list-currencies()' dist/plugin.wasmexchange-rate/
├── src/
│ ├── lib.rs # Main plugin implementation
│ └── types.rs # Data structures for exchange rates
├── wit/
│ └── world.wit # Component interface definition
├── Cargo.toml # Rust dependencies and metadata
├── noorle.yaml # Plugin permissions and configuration
├── build.sh # Build script (used by noorle CLI)
└── dist/ # Build output (created after build)
└── plugin.wasm # Compiled WASM component
Get current exchange rates for a base currency.
Parameters:
base-currency: Base currency code (e.g., "usd", "eur", "gbp")target-currencies: Optional comma-separated list of target currencies to filter results
Returns: Success: JSON string containing exchange rate data:
{
"base_currency": "usd",
"rates": {
"eur": 0.92,
"gbp": 0.79,
"jpy": 149.50
},
"last_updated": "2025-09-23"
}Error: String describing what went wrong
Convert an amount from one currency to another.
Parameters:
from-currency: Source currency code (e.g., "usd", "eur", "gbp")to-currency: Target currency code (e.g., "usd", "eur", "gbp")amount: Amount to convert
Returns: Success: JSON string containing conversion result:
{
"from_currency": "usd",
"to_currency": "eur",
"amount": 100.0,
"converted_amount": 92.0,
"exchange_rate": 0.92,
"last_updated": "2025-09-23"
}Error: String describing what went wrong
List all supported currencies.
Returns: Success: JSON string containing supported currencies:
{
"currencies": {
"usd": "US Dollar",
"eur": "Euro",
"gbp": "British Pound",
"jpy": "Japanese Yen"
}
}Error: String describing what went wrong
[dependencies]
wit-bindgen = "0.46.0" # Component Model bindings generation
anyhow = "1.0" # Error handling
serde = { version = "1.0", features = ["derive"] } # JSON serialization
serde_json = "1.0" # JSON parsing
waki = "0.5" # WASI HTTP client
urlencoding = "2.1" # URL encoding for API parametersBy studying this example, developers learn:
- Fallback Strategies: Implementing reliable API access with multiple endpoints
- Financial Data Handling: Working with currency precision and conversions
- Caching Patterns: Efficient data management in stateless components
- Free API Integration: Building valuable services without API key requirements
- Error Recovery: Graceful degradation when services are unavailable
This example serves as a foundation for building financial tools, data aggregation services, and real-time information plugins.