From eb0b33bfcd0041b3869dbd12da1f33cac2f8ab95 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 02:12:04 +0000 Subject: [PATCH 01/13] Fix code examples in SDK getting started --- docs/sdks/android/GETTING_STARTED.md | 11 ++++++----- docs/sdks/dart/GETTING_STARTED.md | 8 ++++---- docs/sdks/deno/GETTING_STARTED.md | 10 +++++----- docs/sdks/dotnet/GETTING_STARTED.md | 10 ++++------ docs/sdks/flutter/GETTING_STARTED.md | 16 ++++++++-------- docs/sdks/kotlin/GETTING_STARTED.md | 18 ++++++++---------- docs/sdks/nodejs/GETTING_STARTED.md | 6 +++--- docs/sdks/php/GETTING_STARTED.md | 7 ++++--- docs/sdks/python/GETTING_STARTED.md | 5 +++-- docs/sdks/ruby/GETTING_STARTED.md | 6 +++--- docs/sdks/web/GETTING_STARTED.md | 4 ++-- 11 files changed, 50 insertions(+), 51 deletions(-) diff --git a/docs/sdks/android/GETTING_STARTED.md b/docs/sdks/android/GETTING_STARTED.md index 0c00bf6019..4549d7204b 100644 --- a/docs/sdks/android/GETTING_STARTED.md +++ b/docs/sdks/android/GETTING_STARTED.md @@ -51,7 +51,7 @@ When trying to connect to Appwrite from an emulator or a mobile device, localhos // Register User val account = Account(client) val response = account.create( - "[USER_ID]", + ID.unique(), "email@example.com", "password" ) @@ -62,6 +62,7 @@ val response = account.create( ```kotlin import io.appwrite.Client import io.appwrite.services.Account +import io.appwrite.ID val client = Client(context) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint @@ -69,8 +70,8 @@ val client = Client(context) .setSelfSigned(true) // Remove in production val account = Account(client) -val response = account.create( - "[USER_ID]", +val user = account.create( + ID.unique(), "email@example.com", "password" ) @@ -81,8 +82,8 @@ The Appwrite Android SDK raises an `AppwriteException` object with `message`, `c ```kotlin try { - var response = account.create("[USER_ID]", "email@example.com", "password") - Log.d("Appwrite response", response.body?.string()) + var user = account.create(ID.unique(), "email@example.com", "password") + Log.d("Appwrite user", account.toMap()) } catch(e : AppwriteException) { Log.e("AppwriteException",e.message.toString()) } diff --git a/docs/sdks/dart/GETTING_STARTED.md b/docs/sdks/dart/GETTING_STARTED.md index e6c4ecf677..559c0894a3 100644 --- a/docs/sdks/dart/GETTING_STARTED.md +++ b/docs/sdks/dart/GETTING_STARTED.md @@ -16,8 +16,8 @@ void main() async { Users users = Users(client); try { - final response = await users.create(userId: '[USER_ID]', email: ‘email@example.com’,password: ‘password’, name: ‘name’); - print(response.data); + final user = await users.create(userId: ID.unique(), email: ‘email@example.com’,password: ‘password’, name: ‘name’); + print(user.toMap()); } on AppwriteException catch(e) { print(e.message); } @@ -31,8 +31,8 @@ The Appwrite Dart SDK raises `AppwriteException` object with `message`, `code` a Users users = Users(client); try { - final response = await users.create(userId: '[USER_ID]', email: ‘email@example.com’,password: ‘password’, name: ‘name’); - print(response.data); + final user = await users.create(userId: ID.unique(), email: ‘email@example.com’,password: ‘password’, name: ‘name’); + print(user.toMap()); } on AppwriteException catch(e) { //show message to user or do other operation based on error as required print(e.message); diff --git a/docs/sdks/deno/GETTING_STARTED.md b/docs/sdks/deno/GETTING_STARTED.md index 08c9eb461e..6546719a61 100644 --- a/docs/sdks/deno/GETTING_STARTED.md +++ b/docs/sdks/deno/GETTING_STARTED.md @@ -21,8 +21,8 @@ Once your SDK object is set, create any of the Appwrite service objects and choo ```typescript let users = new sdk.Users(client); -let response = await users.create('[USER_ID]', 'email@example.com', 'password'); -console.log(response); +let user = await users.create(ID.unique(), 'email@example.com', 'password'); +console.log(user); ``` ### Full Example @@ -39,8 +39,8 @@ client .setSelfSigned() // Use only on dev mode with a self-signed SSL cert ; -let response = await users.create('[USER_ID]', 'email@example.com', 'password'); -console.log(response); +let user = await users.create(ID.unique(), 'email@example.com', 'password'); +console.log(user); ``` ### Error Handling @@ -50,7 +50,7 @@ The Appwrite Deno SDK raises `AppwriteException` object with `message`, `code` a let users = new sdk.Users(client); try { - let response = await users.create('[USER_ID]', 'email@example.com', 'password'); + let user = await users.create(ID.unique(), 'email@example.com', 'password'); } catch(e) { console.log(e.message); } diff --git a/docs/sdks/dotnet/GETTING_STARTED.md b/docs/sdks/dotnet/GETTING_STARTED.md index cffbce2078..fe8e81499a 100644 --- a/docs/sdks/dotnet/GETTING_STARTED.md +++ b/docs/sdks/dotnet/GETTING_STARTED.md @@ -20,9 +20,8 @@ static async Task Main(string[] args) var users = Users(client); try { - var request = await users.create('[USER_ID]', 'email@example.com', 'password', 'name'); - var response = await request.Content.ReadAsStringAsync(); - Console.WriteLine(response); + var user = await users.create(ID.unique(), 'email@example.com', 'password', 'name'); + Console.WriteLine(user.ToMap()); } catch (AppwriteException e) { Console.WriteLine(e.Message); } @@ -36,9 +35,8 @@ The Appwrite .NET SDK raises `AppwriteException` object with `message`, `code` a var users = Users(client); try { - var request = await users.create('[USER_ID]', 'email@example.com', 'password', 'name'); - var response = await request.Content.ReadAsStringAsync(); - Console.WriteLine(response); + var user = await users.create(ID.unique(), 'email@example.com', 'password', 'name'); + Console.WriteLine(user.ToMap()); } catch (AppwriteException e) { Console.WriteLine(e.Message); } diff --git a/docs/sdks/flutter/GETTING_STARTED.md b/docs/sdks/flutter/GETTING_STARTED.md index a9c121d2b9..78a334e9f7 100644 --- a/docs/sdks/flutter/GETTING_STARTED.md +++ b/docs/sdks/flutter/GETTING_STARTED.md @@ -101,9 +101,9 @@ When trying to connect to Appwrite from an emulator or a mobile device, localhos ```dart // Register User Account account = Account(client); -Response user = await account +final user = await account .create( - userId: '[USER_ID]', + userId: ID.unique(), email: 'me@appwrite.io', password: 'password', name: 'My Name' @@ -129,9 +129,9 @@ void main() { // Register User Account account = Account(client); - Response user = await account + final user = await account .create( - userId: '[USER_ID]', + userId: ID.unique(), email: 'me@appwrite.io', password: 'password', name: 'My Name' @@ -140,14 +140,14 @@ void main() { ``` ### Error Handling -The Appwrite Flutter SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. +The Appwrite Flutter SDK raises `AppwriteException` object with `message`, `type`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. ```dart -Users users = Users(client); +Account account = Account(client); try { - final response = await users.create(userId: '[USER_ID]', email: ‘email@example.com’,password: ‘password’, name: ‘name’); - print(response.data); + final user = await account.create(userId: ID.unique(), email: ‘email@example.com’,password: ‘password’, name: ‘name’); + print(user.toMap()); } on AppwriteException catch(e) { //show message to user or do other operation based on error as required print(e.message); diff --git a/docs/sdks/kotlin/GETTING_STARTED.md b/docs/sdks/kotlin/GETTING_STARTED.md index be4da1a090..a419d36cb1 100644 --- a/docs/sdks/kotlin/GETTING_STARTED.md +++ b/docs/sdks/kotlin/GETTING_STARTED.md @@ -23,12 +23,11 @@ Once your SDK object is set, create any of the Appwrite service objects and choo ```kotlin val users = Users(client) -val response = users.create( - user = "[USER_ID]", +val user = users.create( + user = ID.unique(), email = "email@example.com", password = "password", ) -val json = response.body?.string() ``` ### Full Example @@ -36,6 +35,7 @@ val json = response.body?.string() ```kotlin import io.appwrite.Client import io.appwrite.services.Users +import io.appwrite.ID suspend fun main() { val client = Client(context) @@ -45,12 +45,11 @@ suspend fun main() { .setSelfSigned(true) // Use only on dev mode with a self-signed SSL cert val users = Users(client) - val response = users.create( - user = "[USER_ID]", + val user = users.create( + user = ID.unique(), email = "email@example.com", password = "password", ) - val json = response.body?.string() } ``` @@ -60,18 +59,17 @@ The Appwrite Kotlin SDK raises `AppwriteException` object with `message`, `code` ```kotlin import io.appwrite.Client +import io.appwrite.ID import io.appwrite.services.Users suspend fun main() { val users = Users(client) try { - val response = users.create( - user = "[USER_ID]", + val user = users.create( + user = ID.unique(), email = "email@example.com", password = "password", ) - var jsonString = response.body?.string() ?: "" - } catch (e: AppwriteException) { println(e) } diff --git a/docs/sdks/nodejs/GETTING_STARTED.md b/docs/sdks/nodejs/GETTING_STARTED.md index 7db3288479..70767e159b 100644 --- a/docs/sdks/nodejs/GETTING_STARTED.md +++ b/docs/sdks/nodejs/GETTING_STARTED.md @@ -22,7 +22,7 @@ Once your SDK object is set, create any of the Appwrite service objects and choo ```js let users = new sdk.Users(client); -let promise = users.create('[USER_ID]', 'email@example.com', 'password'); +let promise = users.create(ID.unique(), 'email@example.com', 'password'); promise.then(function (response) { console.log(response); @@ -45,7 +45,7 @@ client ; let users = new sdk.Users(client); -let promise = users.create('[USER_ID]', 'email@example.com', 'password'); +let promise = users.create(ID.unique(), 'email@example.com', 'password'); promise.then(function (response) { console.log(response); @@ -61,7 +61,7 @@ The Appwrite Node SDK raises `AppwriteException` object with `message`, `code` a let users = new sdk.Users(client); try { - let res = await users.create('[USER_ID]', 'email@example.com', 'password'); + let res = await users.create(ID.unique(), 'email@example.com', 'password'); } catch(e) { console.log(e.message); } diff --git a/docs/sdks/php/GETTING_STARTED.md b/docs/sdks/php/GETTING_STARTED.md index 0dcb7f2475..faa3dcf654 100644 --- a/docs/sdks/php/GETTING_STARTED.md +++ b/docs/sdks/php/GETTING_STARTED.md @@ -20,12 +20,13 @@ Once your SDK object is set, create any of the Appwrite service objects and choo ```php $users = new Users($client); -$result = $users->create('email@example.com', 'password'); +$user = $users->create(ID::unique(), 'email@example.com', 'password'); ``` ### Full Example ```php use Appwrite\Client; +use Appwrite\ID; use Appwrite\Services\Users; $client = new Client(); @@ -39,7 +40,7 @@ $client $users = new Users($client); -$result = $users->create('[USER_ID]', 'email@example.com', 'password'); +$user = $users->create(ID::unique(), 'email@example.com', 'password'); ``` ### Error Handling @@ -48,7 +49,7 @@ The Appwrite PHP SDK raises `AppwriteException` object with `message`, `code` an ```php $users = new Users($client); try { - $result = $users->create('[USER_ID]', 'email@example.com', 'password'); + $user = $users->create(ID::unique(), 'email@example.com', 'password'); } catch(AppwriteException $error) { echo $error->message; } diff --git a/docs/sdks/python/GETTING_STARTED.md b/docs/sdks/python/GETTING_STARTED.md index 46a3001ab9..a7772c9f5d 100644 --- a/docs/sdks/python/GETTING_STARTED.md +++ b/docs/sdks/python/GETTING_STARTED.md @@ -30,6 +30,7 @@ result = users.create('[USER_ID]', 'email@example.com', 'password') ```python from appwrite.client import Client from appwrite.services.users import Users +from appwrite.client import ID client = Client() @@ -42,7 +43,7 @@ client = Client() users = Users(client) -result = users.create('[USER_ID]', 'email@example.com', 'password') +result = users.create(ID.unique(), 'email@example.com', 'password') ``` ### Error Handling @@ -51,7 +52,7 @@ The Appwrite Python SDK raises `AppwriteException` object with `message`, `code` ```python users = Users(client) try: - result = users.create('[USER_ID]', 'email@example.com', 'password') + result = users.create(ID.unique(), 'email@example.com', 'password') except AppwriteException as e: print(e.message) ``` diff --git a/docs/sdks/ruby/GETTING_STARTED.md b/docs/sdks/ruby/GETTING_STARTED.md index ff714c103c..da10e1aebc 100644 --- a/docs/sdks/ruby/GETTING_STARTED.md +++ b/docs/sdks/ruby/GETTING_STARTED.md @@ -22,7 +22,7 @@ Once your SDK object is set, create any of the Appwrite service objects and choo ```ruby users = Appwrite::Users.new(client); -result = users.create(userId: '[USER_ID]', email: 'email@example.com', password: 'password'); +user = users.create(userId: Appwrite::ID::unique(), email: 'email@example.com', password: 'password'); ``` ### Full Example @@ -40,7 +40,7 @@ client users = Appwrite::Users.new(client); -result = users.create(userId: '[USER_ID]', email: 'email@example.com', password: 'password'); +user = users.create(userId: Appwrite::ID::unique(), email: 'email@example.com', password: 'password'); ``` ### Error Handling @@ -50,7 +50,7 @@ The Appwrite Ruby SDK raises `Appwrite::Exception` object with `message`, `code` users = Appwrite::Users.new(client); begin - result = users.create(userId: '[USER_ID]', email: 'email@example.com', password: 'password'); + user = users.create(userId: Appwrite::ID::unique(), email: 'email@example.com', password: 'password'); rescue Appwrite::Exception => error puts error.message end diff --git a/docs/sdks/web/GETTING_STARTED.md b/docs/sdks/web/GETTING_STARTED.md index a1d387d7d4..2c09704af2 100644 --- a/docs/sdks/web/GETTING_STARTED.md +++ b/docs/sdks/web/GETTING_STARTED.md @@ -25,7 +25,7 @@ Once your SDK object is set, access any of the Appwrite services and choose any const account = new Account(client); // Register User -account.create('[USER_ID]', 'me@example.com', 'password', 'Jane Doe') +account.create(ID.unique(), 'me@example.com', 'password', 'Jane Doe') .then(function (response) { console.log(response); }, function (error) { @@ -47,7 +47,7 @@ client const account = new Account(client); // Register User -account.create('[USER_ID]', 'me@example.com', 'password', 'Jane Doe') +account.create(ID.unique(), 'me@example.com', 'password', 'Jane Doe') .then(function (response) { console.log(response); }, function (error) { From cb8688a8c3da3a0ccc791224a73c87976a19cbb0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 7 Sep 2022 14:43:50 +1200 Subject: [PATCH 02/13] Update and move swift getting started docs to right location --- .../sdks/{swift-client => apple}/CHANGELOG.md | 0 .../GETTING_STARTED.md | 66 ++++++++------ docs/sdks/swift-server/GETTING_STARTED.md | 83 ----------------- .../sdks/{swift-server => swift}/CHANGELOG.md | 0 docs/sdks/swift/GETTING_STARTED.md | 91 +++++++++++++++++++ 5 files changed, 128 insertions(+), 112 deletions(-) rename docs/sdks/{swift-client => apple}/CHANGELOG.md (100%) rename docs/sdks/{swift-client => apple}/GETTING_STARTED.md (62%) delete mode 100644 docs/sdks/swift-server/GETTING_STARTED.md rename docs/sdks/{swift-server => swift}/CHANGELOG.md (100%) create mode 100644 docs/sdks/swift/GETTING_STARTED.md diff --git a/docs/sdks/swift-client/CHANGELOG.md b/docs/sdks/apple/CHANGELOG.md similarity index 100% rename from docs/sdks/swift-client/CHANGELOG.md rename to docs/sdks/apple/CHANGELOG.md diff --git a/docs/sdks/swift-client/GETTING_STARTED.md b/docs/sdks/apple/GETTING_STARTED.md similarity index 62% rename from docs/sdks/swift-client/GETTING_STARTED.md rename to docs/sdks/apple/GETTING_STARTED.md index 51e5a5bc83..213ab764ac 100644 --- a/docs/sdks/swift-client/GETTING_STARTED.md +++ b/docs/sdks/apple/GETTING_STARTED.md @@ -53,30 +53,35 @@ For UIKit, you need to add the following function to your `SceneDelegate.swift`. ### Init your SDK -Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key project API keys section. +Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page. ```swift import Appwrite func main() { let client = Client() - .setEndpoint("http://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .setProject("5df5acd0d48c2") // Your project ID - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert + .setEndpoint("http://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + .setSelfSigned() // Use only on dev mode with a self-signed SSL cert } ``` ### 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. +Once your SDK object is initialized, 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. ```swift -let users = Users(client: client) -users.create(userId: "[USER_ID]", email: "email@example.com", password: "password") { result in - switch result { - case .failure(let error): print(error.message) - case .success(let user): print(String(describing: user)) - } +let account = Account(client) + +do { + let account = try await account.create( + userId: ID.unique(), + email: "email@example.com", + password: "password" + ) + print(String(describing: account.toMap())) +} catch { + print(error.localizedDescription) } ``` @@ -87,37 +92,40 @@ import Appwrite func main() { let client = Client() - .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .setProject("5df5acd0d48c2") // Your project ID - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + .setSelfSigned() // Use only on dev mode with a self-signed SSL cert - let users = Users(client: client) - users.create(userId: "[USER_ID]", email: "email@example.com", password: "password") { result in - switch result { - case .failure(let error): print(error.message) - case .success(let user): print(String(describing: user)) - } + let account = Account(client) + + do { + let account = try await account.create( + userId: ID.unique(), + email: "email@example.com", + password: "password" + ) + print(String(describing: account.toMap())) + } catch { + print(error.localizedDescription) } } ``` ### Error Handling -When an error occurs, the Appwrite Swift SDK responds with a result wrapping an `AppwriteError` object with `message` and `code` properties. You can handle any errors in the result's `.failure` case and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. +When an error occurs, the Appwrite Apple SDK throws an `AppwriteError` object with `message` and `code` properties. You can handle any errors in a catch block and present the `message` or `localizedDescription` to the user or handle it yourself based on the provided error information. Below is an example. ```swift import Appwrite func main() { - let users = Users(client: client) + let account = Account(client) - users.create(userId: "[USER_ID]", email: "email@example.com", password: "password") { result in - switch result { - case .failure(let error): - print(error.message) - case .success(var response): - ... - } + do { + let account = try await account.get() + print(String(describing: account.toMap())) + } catch { + print(error.localizedDescription) } } ``` diff --git a/docs/sdks/swift-server/GETTING_STARTED.md b/docs/sdks/swift-server/GETTING_STARTED.md deleted file mode 100644 index c27fbb34a0..0000000000 --- a/docs/sdks/swift-server/GETTING_STARTED.md +++ /dev/null @@ -1,83 +0,0 @@ -## Getting Started - -### Init your SDK - -Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key project API keys section. - -```swift -import Appwrite - -func main() { - let client = Client() - .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .setProject("5df5acd0d48c2") // Your project ID - .setKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert -} -``` - -### 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. - -```swift -let users = Users(client: client) -users.create(userId: "[USER_ID]", email: "email@example.com", password: "password") { result in - switch result { - case .failure(let error): print(error.message) - case .success(let user): print(String(describing: user)) - } -} -``` - -### Full Example - -```swift -import Appwrite - -func main() { - let client = Client() - .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .setProject("5df5acd0d48c2") // Your project ID - .setKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert - - let users = Users(client: client) - users.create(userId: "[USER_ID]", email: "email@example.com", password: "password") { result in - switch result { - case .failure(let error): print(error.message) - case .success(let user): print(String(describing: user)) - } - } -} -``` - -### Error Handling - -When an error occurs, the Appwrite Swift SDK responds with a result wrapping an `AppwriteError` object with `message` and `code` properties. You can handle any errors in the result's `.failure` case and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. - -```swift -import Appwrite - -func main() { - let users = Users(client: client) - - users.create(userId: "[USER_ID]", email: "email@example.com", password: "password") { result in - switch result { - case .failure(let error): - print(error.message) - case .success(var response): - ... - } - } -} -``` - -### 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) -- 🚂 [Appwrite Swift Playground](https://github.com/appwrite/playground-for-swift-server) diff --git a/docs/sdks/swift-server/CHANGELOG.md b/docs/sdks/swift/CHANGELOG.md similarity index 100% rename from docs/sdks/swift-server/CHANGELOG.md rename to docs/sdks/swift/CHANGELOG.md diff --git a/docs/sdks/swift/GETTING_STARTED.md b/docs/sdks/swift/GETTING_STARTED.md new file mode 100644 index 0000000000..e0fb45dd7d --- /dev/null +++ b/docs/sdks/swift/GETTING_STARTED.md @@ -0,0 +1,91 @@ +## Getting Started + +### Init your SDK + +Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key project API keys section. + +```swift +import Appwrite + +func main() { + let client = Client() + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + .setKey("919c2d184...a2ae413dad2") // Your secret API key + .setSelfSigned() // Use only on dev mode with a self-signed SSL cert +} +``` + +### Make Your First Request + +Once your SDK object is initialized, 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. + +```swift +let users = Users(client) + +do { + let user = try await users.create( + userId: ID.unique(), + email: "email@example.com", + password: "password" + ) + print(String(describing: user.toMap())) +} catch { + print(error.localizedDescription) +} +``` + +### Full Example + +```swift +import Appwrite + +func main() { + let client = Client() + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + .setKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key + .setSelfSigned() // Use only on dev mode with a self-signed SSL cert + + let users = Users(client) + + do { + let user = try await users.create( + userId: ID.unique(), + email: "email@example.com", + password: "password" + ) + print(String(describing: user.toMap())) + } catch { + print(error.localizedDescription) + } +} +``` + +### Error Handling + +When an error occurs, the Appwrite Swift SDK throws an `AppwriteError` object with `message` and `code` properties. You can handle any errors in a catch block and present the `message` or `localizedDescription` to the user or handle it yourself based on the provided error information. Below is an example. + +```swift +import Appwrite + +func main() { + let users = Users(client) + + do { + let users = try await users.list() + print(String(describing: users.toMap())) + } catch { + print(error.localizedDescription) + } +} +``` + +### 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) +- 🚂 [Appwrite Swift Playground](https://github.com/appwrite/playground-for-swift-server) From fb3ba9a47512a98901041603bc55096c73beea8a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:05:38 +0545 Subject: [PATCH 03/13] Update docs/sdks/android/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/android/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/android/GETTING_STARTED.md b/docs/sdks/android/GETTING_STARTED.md index 4549d7204b..bb312390fc 100644 --- a/docs/sdks/android/GETTING_STARTED.md +++ b/docs/sdks/android/GETTING_STARTED.md @@ -85,7 +85,7 @@ try { var user = account.create(ID.unique(), "email@example.com", "password") Log.d("Appwrite user", account.toMap()) } catch(e : AppwriteException) { - Log.e("AppwriteException",e.message.toString()) + e.printStackTrace() } ``` From e24d789510fc54ced6d1e3b3e51f1783f4bcd622 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:05:44 +0545 Subject: [PATCH 04/13] Update docs/sdks/apple/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/apple/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/apple/GETTING_STARTED.md b/docs/sdks/apple/GETTING_STARTED.md index 213ab764ac..755fa4f93b 100644 --- a/docs/sdks/apple/GETTING_STARTED.md +++ b/docs/sdks/apple/GETTING_STARTED.md @@ -74,7 +74,7 @@ Once your SDK object is initialized, create any of the Appwrite service objects let account = Account(client) do { - let account = try await account.create( + let user = try await account.create( userId: ID.unique(), email: "email@example.com", password: "password" From 50d20f7e840b82698c6e1e71a5fc3a2107541f57 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:05:50 +0545 Subject: [PATCH 05/13] Update docs/sdks/android/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/android/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/android/GETTING_STARTED.md b/docs/sdks/android/GETTING_STARTED.md index bb312390fc..684f98e0f6 100644 --- a/docs/sdks/android/GETTING_STARTED.md +++ b/docs/sdks/android/GETTING_STARTED.md @@ -83,7 +83,7 @@ The Appwrite Android SDK raises an `AppwriteException` object with `message`, `c ```kotlin try { var user = account.create(ID.unique(), "email@example.com", "password") - Log.d("Appwrite user", account.toMap()) + Log.d("Appwrite user", user.toMap()) } catch(e : AppwriteException) { e.printStackTrace() } From a342a77caf720261571efbb7a31823dd2a4a04ef Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:05:56 +0545 Subject: [PATCH 06/13] Update docs/sdks/apple/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/apple/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/apple/GETTING_STARTED.md b/docs/sdks/apple/GETTING_STARTED.md index 755fa4f93b..129947ad24 100644 --- a/docs/sdks/apple/GETTING_STARTED.md +++ b/docs/sdks/apple/GETTING_STARTED.md @@ -79,7 +79,7 @@ do { email: "email@example.com", password: "password" ) - print(String(describing: account.toMap())) + print(String(describing: user.toMap())) } catch { print(error.localizedDescription) } From 4acd4a03d32f55d9033c321a24fd1720cac5652c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:06:02 +0545 Subject: [PATCH 07/13] Update docs/sdks/apple/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/apple/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/apple/GETTING_STARTED.md b/docs/sdks/apple/GETTING_STARTED.md index 129947ad24..bbc9b085f3 100644 --- a/docs/sdks/apple/GETTING_STARTED.md +++ b/docs/sdks/apple/GETTING_STARTED.md @@ -123,7 +123,7 @@ func main() { do { let account = try await account.get() - print(String(describing: account.toMap())) + print(String(describing: user.toMap())) } catch { print(error.localizedDescription) } From 0fd027b957f2cddaa991a4ab28136baba569affd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:06:33 +0545 Subject: [PATCH 08/13] Update docs/sdks/dotnet/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/dotnet/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/dotnet/GETTING_STARTED.md b/docs/sdks/dotnet/GETTING_STARTED.md index fe8e81499a..46396c106c 100644 --- a/docs/sdks/dotnet/GETTING_STARTED.md +++ b/docs/sdks/dotnet/GETTING_STARTED.md @@ -20,7 +20,7 @@ static async Task Main(string[] args) var users = Users(client); try { - var user = await users.create(ID.unique(), 'email@example.com', 'password', 'name'); + var user = await users.Create(ID.Unique(), 'email@example.com', 'password', 'name'); Console.WriteLine(user.ToMap()); } catch (AppwriteException e) { Console.WriteLine(e.Message); From 90e05fec8785320e4cd5a91a2b376e26cf281d12 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:06:38 +0545 Subject: [PATCH 09/13] Update docs/sdks/dotnet/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/dotnet/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/dotnet/GETTING_STARTED.md b/docs/sdks/dotnet/GETTING_STARTED.md index 46396c106c..23bab6f70a 100644 --- a/docs/sdks/dotnet/GETTING_STARTED.md +++ b/docs/sdks/dotnet/GETTING_STARTED.md @@ -35,7 +35,7 @@ The Appwrite .NET SDK raises `AppwriteException` object with `message`, `code` a var users = Users(client); try { - var user = await users.create(ID.unique(), 'email@example.com', 'password', 'name'); + var user = await users.Create(ID.Unique(), 'email@example.com', 'password', 'name'); Console.WriteLine(user.ToMap()); } catch (AppwriteException e) { Console.WriteLine(e.Message); From b7e9d4894edf8e177d1f7fa9abe3ee6b54b945a5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:06:43 +0545 Subject: [PATCH 10/13] Update docs/sdks/kotlin/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/kotlin/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/kotlin/GETTING_STARTED.md b/docs/sdks/kotlin/GETTING_STARTED.md index a419d36cb1..99d5e719af 100644 --- a/docs/sdks/kotlin/GETTING_STARTED.md +++ b/docs/sdks/kotlin/GETTING_STARTED.md @@ -71,7 +71,7 @@ suspend fun main() { password = "password", ) } catch (e: AppwriteException) { - println(e) + e.printStackTrace() } } ``` From f18707c3a03b388069cfac1cba366f98d9d8e284 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:06:51 +0545 Subject: [PATCH 11/13] Update docs/sdks/python/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/python/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/python/GETTING_STARTED.md b/docs/sdks/python/GETTING_STARTED.md index a7772c9f5d..9f693b65c6 100644 --- a/docs/sdks/python/GETTING_STARTED.md +++ b/docs/sdks/python/GETTING_STARTED.md @@ -30,7 +30,7 @@ result = users.create('[USER_ID]', 'email@example.com', 'password') ```python from appwrite.client import Client from appwrite.services.users import Users -from appwrite.client import ID +from appwrite.id import ID client = Client() From af1d1dd7a27eeca05f3227594501b8968eeda40b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 7 Sep 2022 11:06:59 +0545 Subject: [PATCH 12/13] Update docs/sdks/apple/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/apple/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/apple/GETTING_STARTED.md b/docs/sdks/apple/GETTING_STARTED.md index bbc9b085f3..de2f233189 100644 --- a/docs/sdks/apple/GETTING_STARTED.md +++ b/docs/sdks/apple/GETTING_STARTED.md @@ -99,7 +99,7 @@ func main() { let account = Account(client) do { - let account = try await account.create( + let user = try await account.create( userId: ID.unique(), email: "email@example.com", password: "password" From f6868318e06d0b781ec33a3a8e05ae3bdc4da7fe Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 13 Sep 2022 21:54:57 +0530 Subject: [PATCH 13/13] Update docs/sdks/apple/GETTING_STARTED.md Co-authored-by: Jake Barnby --- docs/sdks/apple/GETTING_STARTED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sdks/apple/GETTING_STARTED.md b/docs/sdks/apple/GETTING_STARTED.md index de2f233189..1da041112c 100644 --- a/docs/sdks/apple/GETTING_STARTED.md +++ b/docs/sdks/apple/GETTING_STARTED.md @@ -122,7 +122,7 @@ func main() { let account = Account(client) do { - let account = try await account.get() + let user = try await account.get() print(String(describing: user.toMap())) } catch { print(error.localizedDescription)