Build Status

bridge.rs

Prima bridge pattern implementation for rust

Api documentation

Example

```rust use serde::Deserialize; use primabridge::prelude::*; use oncecell::sync::OnceCell;

[derive(Deserialize, Debug)]

pub struct MyCustomData { name: String }

// using OnceCell we make sure that Bridge gets instantiated only once fn bridge() -> &'static Bridge { static BRIDGE: OnceCell = OnceCell::new(); BRIDGE.getorinit(|| Bridge::new("https://swapi.dev/api".parse().unwrap())) }

pub fn fetchdata() -> Result { Request::get(bridge()) .to("people/1") .send()? .getdata(&[]) }

fn main() { let data = fetch_data().expect("there was an error while fetching data"); println!("the name is {}", data.name); }
```

To understand this example you should know: - once_cell library providing the cell type - Rust error handling to use ? and convert it to a custom error type. See for example thiserror