bridge.rs
Prima bridge pattern implementation for rust
Example
use *;
use Deserialize;
// using once_cell we make sure that `Bridge` get instantiated only once
To understand this example you should know:
Prima bridge pattern implementation for rust
use prima_bridge::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct DeserializableData {
test: String
}
// using once_cell we make sure that `Bridge` get instantiated only once
fn bridge() -> &'static Bridge {
static BRIDGE: OnceCell<Bridge> = OnceCell::new();
BRIDGE.get_or_init(|| Bridge::new("https://prima.it/api"))
}
pub fn fetch_data() -> YourResult<DeserializableData> {
Request::get(bridge())
.send()?
.get_data(&["nested", "selector"])? // response is {"nested": {"selector": {"data": "test"}}}
}
To understand this example you should know: