diff --git a/docs/sdks/android/GETTING_STARTED.md b/docs/sdks/android/GETTING_STARTED.md index 0c00bf6019..684f98e0f6 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,10 +82,10 @@ 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", user.toMap()) } catch(e : AppwriteException) { - Log.e("AppwriteException",e.message.toString()) + e.printStackTrace() } ``` 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..1da041112c 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 user = try await account.create( + userId: ID.unique(), + email: "email@example.com", + password: "password" + ) + print(String(describing: user.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 user = 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 user = try await account.get() + print(String(describing: user.toMap())) + } catch { + print(error.localizedDescription) } } ``` 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..23bab6f70a 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..99d5e719af 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,20 +59,19 @@ 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) + e.printStackTrace() } } ``` 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..9f693b65c6 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.id 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/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) 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) {