PUT - Store Data
To store data on a homeserver, use the put
method on the session's storage. In Pubky, you work with a PubkySession
that provides authenticated access.
async fn put() -> pubky::Result<()> {
let pubky = Pubky::new()?;
let keypair = Keypair::random();
let signer = pubky.signer(keypair);
// The homeserver's public key
let homeserver = PublicKey::try_from("o4dksfbqk85ogzdb5osziw6befigbuxmuxkuxq8434q89uj56uyy")
.expect("Valid homeserver public key");
// Sign up to the homeserver
let session = signer.signup(&homeserver, None).await?;
// The content to store
let content = "Hello, Pubky!";
// PUT the content to the homeserver
session.storage().put("/pub/example.txt", content).await?;
println!("Successfully stored data");
Ok(())
}
The PUT operation:
- Requires a
PubkySession
obtained from signing up or signing in - Takes a path (not a full URL) relative to your homeserver
- Accepts data in various formats (strings, bytes, etc.)
- Creates or overwrites the data at the specified path
- All operations are authenticated using your session