Crates.io | pasty-rs |
lib.rs | pasty-rs |
version | 0.1.0 |
source | src |
created_at | 2024-02-24 22:00:36.751777 |
updated_at | 2024-02-24 22:00:36.751777 |
description | A low level API wrapper for pasty. |
homepage | |
repository | https://github.com/zekrotja/pasty-rs |
max_upload_size | |
id | 1151952 |
size | 12,096 |
A low level API wrapper for pasty.
cargo add pasty-rs
Because this SDK currently only allows async requests, you might want to install an async runtime like tokio, async-std or smol.
The following example uses tokio as async runtime.
cargo add tokio --features all
use pasty_rs::client::UnauthenticatedClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create an API client for unauthenticated requests.
let client = UnauthenticatedClient::new("https://pasty.lus.pm")?;
// Create a paste.
let paste = client.create_paste("hello pasty!", None).await?;
dbg!(&paste);
// Store the modification_token of that paste.
let modification_token = paste.modification_token;
// Get a paste by id (the one we've created).
let paste = client.paste(&paste.paste.id).await?;
dbg!(&paste);
// Transform the unauthenticated client into an authenticated client
// using the modification_token of the created paste.
let client = client.authenticate(&modification_token);
// Update the previously created paste with the authenticated client.
client
.update_paste(&paste.id, "new hello world", None)
.await?;
// Retireve the updated posts content.
let paste = client.inner().paste(&paste.id).await?;
dbg!(&paste);
// Delete the created post.
client.delete_paste(&paste.id).await?;
Ok(())
}
Because this is a somewhat quick and dirty implementation I need for another project, this crate currently has some limitations.
This crate is licensed under the MIT License.
pasty is licensed under the MIT License, (c) 2020 Lukas SP.