2 unstable releases
0.5.0 | Oct 28, 2024 |
---|---|
0.0.0 | Oct 26, 2024 |
#694 in Encoding
278 downloads per month
16KB
417 lines
installation:
cargo add pb-sdk
or add to cargo.toml
[dependencies]
pb-sdk = "0.5.0"
example usage:
use pb_sdk::{PbAdminClient, GetListSuccess};
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
struct Post {
id: String,
name: String,
content: String
}
#[derive(Serialize)]
struct CreatePost {
name: String,
content: String
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>>{
// authenticate
let client = PbAdminClient::new("http://localhost:8090").auth_with_password("admin_username@example.com", "admin_password").await?;
// list posts
let posts: GetListSuccess<Post> = client.collection("posts").unwrap().get_list(1, 50).call().await?;
// view post
let post: Post = client.collection("posts").unwrap().get_one("s42mpy041qkmnzp").call().await?;
// create post
let new_post = CreatePost {
name: "wood".to_string(),
content: "yes".to_string()
};
let create_resp: Post = client.collection("posts").unwrap().create(new_post).call().await?;
// update post
let updated_post = CreatePost {
name: "not_wood".to_string(),
content: "no".to_string()
};
let updated_post: Post = client.collection("posts").unwrap().update("s42mpy041qkmnzp", updated_post).call().await?;
// delete post
client.collection("posts").unwrap().delete("yqh6x1oz9sesnc2").call().await?;
Ok(())
}
Dependencies
~4–15MB
~194K SLoC