From db278a5cb30e03b2ff4a53970876cd2fb859e274 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 17 Oct 2026 15:32:33 +0100 Subject: [PATCH] docs: refresh README --- README.md | 108 +++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 26523cf..0001d27 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Appwrite Rust SDK -![License](https://img.shields.io/github/license/appwrite/sdk-for-rust.svg) +![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg) ![Version](https://img.shields.io/badge/api%20version-2.5.0-blue.svg) [![Crates.io](https://img.shields.io/crates/v/appwrite.svg)](https://crates.io/crates/appwrite) [![Documentation](https://docs.rs/appwrite/badge.svg)](https://docs.rs/appwrite) @@ -25,82 +25,92 @@ Or using `cargo add`: ```bash cargo add appwrite +cargo add tokio --features full ``` +The SDK is async and runs on the [Tokio](https://tokio.rs) runtime. ## Getting Started ### Init your SDK -Initialize your SDK with your Appwrite server API endpoint and project ID which can be found on your project settings page and your new API secret Key from project's API keys section. + +Create a client with your Appwrite API endpoint, project ID and an API key. You can find the project ID in your project settings, and create an API key with the scopes you need in your project's API keys section. ```rust -use appwrite::client::Client; +use appwrite::Client; let client = Client::new() - .set_endpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .set_project("5df5acd0d48c2") // Your project ID - .set_key("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key - .set_self_signed(true); // Use only on dev mode with a self-signed SSL cert + .set_endpoint("https://.cloud.appwrite.io/v1") + .set_project("") + .set_key(""); ``` -### Make Your First Request -Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section. +If you self-host Appwrite, use your own endpoint, such as `https:///v1`. Add `.set_self_signed(true)` only in development, when your server uses a self-signed certificate. + +### Make your first request + +Create a service from the client and call any of its methods. Every method is `async` and returns `appwrite::Result`. Optional parameters take an `Option`; pass `None` to skip one. ```rust -use appwrite::client::Client; -use appwrite::services::users::Users; use appwrite::id::ID; - -let client = Client::new() - .set_endpoint("https://[HOSTNAME_OR_IP]/v1") - .set_project("5df5acd0d48c2") - .set_key("919c2d18fb5d4...a2ae413da83346ad2") - .set_self_signed(true); - -let users = Users::new(&client); - -let user = users.create( - ID::unique(), - Some("email@example.com"), - Some("+123456789"), - Some("password"), - Some("Walter O'Brien"), -).await?; - -println!("{}", user.name); -println!("{}", user.email); +use appwrite::services::Users; +use appwrite::Client; + +#[tokio::main] +async fn main() -> appwrite::Result<()> { + let client = Client::new() + .set_endpoint("https://.cloud.appwrite.io/v1") + .set_project("") + .set_key(""); + + let users = Users::new(&client); + + let user = users + .create( + ID::unique(), + Some("email@example.com"), + None, + Some("password"), + Some("Walter O'Brien"), + ) + .await?; + + println!("{} {} {}", user.id, user.name, user.email); + + Ok(()) +} ``` -### Error Handling -The Appwrite Rust SDK returns `Result` types. You can handle errors using standard Rust error handling patterns. Below is an example. +### Error handling + +Failed requests return an `AppwriteError` with the HTTP status `code`, the `message`, the error type and the raw `response` body. ```rust -use appwrite::error::AppwriteError; - -match users.create( - ID::unique(), - Some("email@example.com"), - Some("+123456789"), - Some("password"), - Some("Walter O'Brien"), -).await { +match users + .create(ID::unique(), Some("email@example.com"), None, None, None) + .await +{ Ok(user) => println!("{}", user.name), - Err(AppwriteError { message, code, .. }) => { - eprintln!("Error {}: {}", code, message); - } + Err(error) => eprintln!( + "Appwrite error {} ({}): {}", + error.code, + error.get_type().unwrap_or("unknown"), + error.message + ), } ``` ### Learn more -You can use the following resources to learn more and get help -- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server) -- 📜 [Appwrite Docs](https://appwrite.io/docs) -- 💬 [Discord Community](https://appwrite.io/discord) +- [Rust quick start](https://appwrite.io/docs/quick-starts/rust) +- [Rust API reference](https://appwrite.io/docs/references/cloud/server-rust) +- [Crate documentation](https://docs.rs/appwrite) +- [Appwrite docs](https://appwrite.io/docs) +- [Discord community](https://appwrite.io/discord) ## Contribution -This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request. +This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/main/CONTRIBUTING.md) before sending a pull-request. ## License