Merge pull request #3777 from appwrite/doc-sdk-getting-started-examples

Fix code examples in SDK getting started
This commit is contained in:
Christy Jacob 2022-09-14 01:23:42 +04:00 committed by GitHub
commit 421db5b224
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 180 additions and 165 deletions

View file

@ -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()
}
```

View file

@ -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)
}
}
```

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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()
}
}
```

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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)
```

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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) {