diff --git a/src/routes/docs/quick-starts/+page.svelte b/src/routes/docs/quick-starts/+page.svelte index 94ce6cf70b..c4509bb4ff 100644 --- a/src/routes/docs/quick-starts/+page.svelte +++ b/src/routes/docs/quick-starts/+page.svelte @@ -112,7 +112,37 @@ icon: 'icon-dart', image: '/images/blog/placeholder.png', href: 'dart' - } + }, + { + title: 'Ruby', + icon: 'icon-ruby', + image: '/images/blog/placeholder.png', + href: 'ruby' + }, + { + title: 'Deno', + icon: 'icon-deno', + image: '/images/blog/placeholder.png', + href: 'deno' + }, + { + title: 'PHP', + icon: 'icon-php', + image: '/images/blog/placeholder.png', + href: 'php' + }, + { + title: 'Kotlin', + icon: 'icon-kotlin', + image: '/images/blog/placeholder.png', + href: 'kotlin' + }, + { + title: 'Swift', + icon: 'icon-swift', + image: '/images/blog/placeholder.png', + href: 'swift' + }, ] } ]; diff --git a/src/routes/docs/quick-starts/dart/+page.markdoc b/src/routes/docs/quick-starts/dart/+page.markdoc index a289ea48ce..ffb4fbbc64 100644 --- a/src/routes/docs/quick-starts/dart/+page.markdoc +++ b/src/routes/docs/quick-starts/dart/+page.markdoc @@ -24,8 +24,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | | | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | | | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | -| | `documents.read` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | -| | `documents.write` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/deno/+page.markdoc b/src/routes/docs/quick-starts/deno/+page.markdoc new file mode 100644 index 0000000000..0f8737a6c6 --- /dev/null +++ b/src/routes/docs/quick-starts/deno/+page.markdoc @@ -0,0 +1,221 @@ +--- +layout: article +title: Start with Deno +description: Dive into our step-by-step guide on integrating Appwrite with your Deno server backend application. Get your backend up and running quickly with this tutorial. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Deno project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +If this is your first time using Appwrite, create an account and create your first project. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} + +| Category {% width=120 %} | Required scopes | Purpose | +|-----------|-----------------------|---------| +| Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | +| | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | +| | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | + +Other scopes are optional. + +{% /section %} +{% section #step-2 step=2 title="Create Deno project" %} +Create a Deno CLI application. + +```sh +mkdir my-app +cd my-app +echo "console.log('Hello, Deno!');" > mod.ts +``` + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Deno Appwrite SDK by importing it `deno.land/x` at the top of your file. + +``` +// import all as sdk +import * as sdk from "https://deno.land/x/appwrite/mod.ts"; + +// import only what you need +import { Client, ... other imports } from "https://deno.land/x/appwrite/mod.ts"; +``` + +{% /section %} +{% section #step-4 step=4 title="Import Appwrite" %} + +Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Open `mod.ts` in your IDE and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```ts +import { Client, ID, Databases, Models } from "https://deno.land/x/appwrite/mod.ts"; + +const client: Client = new Client(); + +client + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```ts +const databases: Databases = new Databases(client); + +var todoDatabase: Models.Database; +var todoCollection: Models.Collection; + +interface Todo { + title: string; + description: string; + isComplete?: boolean; +} + +async function prepareDatabase(): Promise { + todoDatabase = await databases.create( + ID.unique(), + 'TodosDB' + ); + + todoCollection = await databases.createCollection( + todoDatabase.$id, + ID.unique(), + 'Todos' + ); + + await databases.createStringAttribute( + todoDatabase.$id, + todoCollection.$id, + 'title', + 255, + true + ); + + await databases.createStringAttribute( + todoDatabase.$id, + todoCollection.$id, + 'description', + 255, false, + 'This is a test description' + ); + + await databases.createBooleanAttribute( + todoDatabase.$id, + todoCollection.$id, + 'isComplete', + true + ); +} +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. + +```ts +async function seedDatabase(): Promise { + const testTodo1: Todo = { + title: 'Buy apples', + description: 'At least 2KGs', + isComplete: true + }; + + const testTodo2: Todo = { + title: 'Wash the apples', + isComplete: true + }; + + const testTodo3: Todo = { + title: 'Cut the apples', + description: 'Don\'t forget to pack them in a box', + isComplete: false + }; + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + ID.unique(), + testTodo1 + ); + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + ID.unique(), + testTodo2 + ); + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + ID.unique(), + testTodo3 + ); +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +Create a function to retrieve the mock todo data and a function to execute the requests in order. +Run the functions to by calling `runAllTasks();`. + +```ts +async function getTodos(): Promise { + const todos = await databases.listDocuments( + todoDatabase.$id, + todoCollection.$id + ); + + todos.documents.forEach((todo: Todo) => { + console.log(`Title: ${todo.title}\nDescription: ${todo.description}\nIs Todo Complete: ${todo.isComplete}\n\n`); + }); +} + +async function runAllTasks(): Promise { + await prepareDatabase(); + await seedDatabase(); + await getTodos(); +} +runAllTasks(); +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with `deno mod.ts` and view the response in your console. + +{% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/dotnet/+page.markdoc b/src/routes/docs/quick-starts/dotnet/+page.markdoc index d16f6b4970..15e75b5ac5 100644 --- a/src/routes/docs/quick-starts/dotnet/+page.markdoc +++ b/src/routes/docs/quick-starts/dotnet/+page.markdoc @@ -32,8 +32,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | | | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | | | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | -| | `documents.read` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | -| | `documents.write` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc new file mode 100644 index 0000000000..a7cc031cc9 --- /dev/null +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -0,0 +1,217 @@ +--- +layout: article +title: Start with Kotlin +description: Learn to get started with server integrations with Appwrite Kotlin SDK. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Kotlin project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +{% info title="Server SDK" %} +This tutorial is for the Kotlin Server SDK, meant for server and backend applications. +If you're trying to build a client-side app, like an Android app, +follow the [Start with Android guide](https://appwrite.io/docs/quick-starts/android). +{% /info %} + +If this is your first time using Appwrite, create an account and create your first project. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Server integrations](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Server integrations](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} +| Category {% width=120 %} | Required scopes | Purpose | +|-----------|-----------------------|---------| +| Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | +| | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | +| | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | + +Other scopes are optional. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +{% /section %} +{% section #step-2 step=2 title="Create Kotlin project" %} +Create a Kotlin application by opening **IntelliJ IDEA** > **New Project** and create a **Kotlin** application. +This quick start will use **Gradle** as the build system, with the Kotlin DSL. You can follow with Maven or IntelliJ if you're more comfortable. + +Follow the wizard and open your new project. + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} +Open your `build.gradle.kts` file and implement the following dependency. + +```groovy +dependencies { + ... other dependencies + implementation("io.appwrite:sdk-for-kotlin:4.1.0") +} +``` + +{% /section %} +{% section #step-4 step=4 title="Import Appwrite" %} + +Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Open the file `Main.kt` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```kotlin +import io.appwrite.Client +import io.appwrite.ID +import io.appwrite.services.Databases +import io.appwrite.models.Database +import io.appwrite.models.Collection +import kotlinx.coroutines.coroutineScope + +val client = Client() + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```kotlin +val databases = Databases(client) + +var todoDatabase: Database? = null +var todoCollection: Collection? = null + +suspend fun prepareDatabase() { + todoDatabase = databases.create(ID.unique(), "TodosDB") + todoCollection = databases.createCollection(todoDatabase?.id!!, ID.unique(), "Todos") + + databases.createStringAttribute( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + key = "title", + size = 255, + required = true + ) + + databases.createStringAttribute( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + key = "description", + size = 255, + required = false, + default = "This is a test description." + ) + + databases.createBooleanAttribute( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + key = "isComplete", + required = true + ) +} +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. +```kotlin +suspend fun seedDatabase() { + val testTodo1 = mapOf( + "title" to "Buy apples", + "description" to "At least 2KGs", + "isComplete" to true + ) + + val testTodo2 = mapOf( + "title" to "Wash the apples", + "isComplete" to true + ) + + val testTodo3 = mapOf( + "title" to "Cut the apples", + "description" to "Don't forget to pack them in a box", + "isComplete" to false + ) + + databases.createDocument( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + documentId = ID.unique(), + data = testTodo1 + ) + + databases.createDocument( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + documentId = ID.unique(), + data = testTodo2 + ) + + databases.createDocument( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + documentId = ID.unique(), + data = testTodo3 + ) +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +Create a function to retrieve the mock todo data. + +```kotlin +suspend fun getTodos() { + val todos = databases.listDocuments(todoDatabase?.id!!, todoCollection?.id!!) + for (todo in todos.documents) { + println( + """ + Title: ${todo.data["title"]} + Description: ${todo.data["description"]} + Is Todo Complete: ${todo.data["isComplete"]} + """.trimIndent() + ) + } +} + +suspend fun main() = coroutineScope { + prepareDatabase() + seedDatabase() + getTodos() +} +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with IntelliJ and view the response in your console. + +{% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc index dda4237883..0a4585eb3c 100644 --- a/src/routes/docs/quick-starts/node/+page.markdoc +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -33,8 +33,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | | | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | | | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | -| | `documents.read` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | -| | `documents.write` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/php/+page.markdoc b/src/routes/docs/quick-starts/php/+page.markdoc new file mode 100644 index 0000000000..2df153d113 --- /dev/null +++ b/src/routes/docs/quick-starts/php/+page.markdoc @@ -0,0 +1,217 @@ +--- +layout: article +title: Start with PHP +description: Dive into our step-by-step guide on integrating Appwrite with your PHP server backend application. Get your backend up and running quickly with this tutorial. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first PHP project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +If this is your first time using Appwrite, create an account and create your first project. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} + +| Category {% width=120 %} | Required scopes | Purpose | +|-----------|-----------------------|---------| +| Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | +| | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | +| | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | + +Other scopes are optional. + +{% /section %} +{% section #step-2 step=2 title="Create PHP project" %} +Create a PHP CLI application. + +```sh +mkdir my-app +cd my-app +composer init +``` + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the PHP Appwrite SDK. + +```sh +composer require appwrite/appwrite +``` +{% /section %} +{% section #step-4 step=4 title="Import Appwrite" %} + +Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Create a new file `index.php` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```php +setEndpoint('https://cloud.appwrite.io/v1') + ->setProject('') + ->setKey(''); +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```php +$databases = new Databases($client); + +function prepareDatabase($databases) { + $todoDatabase = $databases->create( + databaseId: ID::unique(), + name: 'TodosDB' + ); + + $todoCollection = $databases->createCollection( + databaseId: $todoDatabase['$id'], + collectionId: ID::unique(), + name: 'Todos' + ); + + $databases->createStringAttribute( + databaseId: $todoDatabase['$id'], + collectionId: $todoCollection['$id'], + key: 'title', + size: 255, + required: true + ); + + $databases->createStringAttribute( + databaseId: $todoDatabase['$id'], + collectionId: $todoCollection['$id'], + key: 'description', + size: 255, + required: false, + ); + + $databases->createBooleanAttribute( + databaseId: $todoDatabase['$id'], + collectionId: $todoCollection['$id'], + key: 'isComplete', + required: true + ); + + return [$todoDatabase, $todoCollection]; +} +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. + +```php +function seedDatabase($databases, $todoDatabase, $todoCollection) { + $testTodo1 = [ + 'title' => 'Buy apples', + 'description' => 'At least 2KGs', + 'isComplete' => true + ]; + + $testTodo2 = [ + 'title' => 'Wash the apples', + 'isComplete' => true + ]; + + $testTodo3 = [ + 'title' => 'Cut the apples', + 'description' => 'Don\'t forget to pack them in a box', + 'isComplete' => false + ]; + + $databases->createDocument( + $todoDatabase['$id'], + $todoCollection['$id'], + ID::unique(), + $testTodo1 + ); + + $databases->createDocument( + $todoDatabase['$id'], + $todoCollection['$id'], + ID::unique(), + $testTodo2 + ); + + $databases->createDocument( + $todoDatabase['$id'], + $todoCollection['$id'], + ID::unique(), + $testTodo3 + ); +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +Create a function to retrieve the mock todo data and a function to execute the requests in order. +Run the functions to by calling `runAllTasks();`. + +```php +function getTodos($databases, $todoDatabase, $todoCollection) { + $todos = $databases->listDocuments( + $todoDatabase['$id'], + $todoCollection['$id'] + ); + + foreach ($todos['documents'] as $todo) { + echo "Title: {$todo['title']}\n" . + "Description: {$todo['description']}\n" . + "Is Todo Complete: {$todo['isComplete']}\n\n"; + } +} + +function runAllTasks($databases) { + [$todoDatabase, $todoCollection] = prepareDatabase($databases); + seedDatabase($databases, $todoDatabase, $todoCollection); + getTodos($databases, $todoDatabase, $todoCollection); +} + +runAllTasks($databases); +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with `php src/index.php` and view the response in your console. + +{% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/python/+page.markdoc b/src/routes/docs/quick-starts/python/+page.markdoc index bda9228ede..94cb68c900 100644 --- a/src/routes/docs/quick-starts/python/+page.markdoc +++ b/src/routes/docs/quick-starts/python/+page.markdoc @@ -33,8 +33,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | | | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | | | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | -| | `documents.read` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | -| | `documents.write` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/ruby/+page.markdoc b/src/routes/docs/quick-starts/ruby/+page.markdoc new file mode 100644 index 0000000000..2df80647cb --- /dev/null +++ b/src/routes/docs/quick-starts/ruby/+page.markdoc @@ -0,0 +1,216 @@ +--- +layout: article +title: Start with Ruby +description: Dive into our step-by-step guide on integrating Appwrite with your Ruby server backend application. Get your backend up and running quickly with this tutorial. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Ruby project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +If this is your first time using Appwrite, create an account and create your first project. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} + +| Category {% width=120 %} | Required scopes | Purpose | +|-----------|-----------------------|---------| +| Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | +| | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | +| | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | + +Other scopes are optional. + +{% /section %} +{% section #step-2 step=2 title="Create Ruby project" %} +Create a Ruby CLI application. + +```sh +mkdir my-app +cd my-app +bundle init +``` + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Ruby Appwrite SDK. + +```sh +bundle add appwrite +``` +{% /section %} +{% section #step-4 step=4 title="Import Appwrite" %} + +Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Create a new file `app.rb` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```ruby +# Initialize the Appwrite client +require 'appwrite' + +include Appwrite + +client = Client.new() + +client + .set_endpoint('https://cloud.appwrite.io/v1') # Your Appwrite Endpoint + .set_project('') # Your project ID + .set_key('') # Your secret API key +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```ruby +databases = Databases.new(client) + +todo_database = nil +todo_collection = nil + +def prepare_database(databases) + todo_database = databases.create( + database_id: ID.unique(), + name: 'TodosDB' + ) + + todo_collection = databases.create_collection( + database_id: todo_database.id, + collection_id: ID.unique(), + name: 'Todos' + ) + + databases.create_string_attribute( + database_id: todo_database.id, + collection_id: todo_collection.id, + key: 'title', + size: 255, + required: true + ) + + databases.create_string_attribute( + database_id: todo_database.id, + collection_id: todo_collection.id, + key: 'description', + size: 255, + required: false + ) + + databases.create_boolean_attribute( + database_id: todo_database.id, + collection_id: todo_collection.id, + key: 'isComplete', + required: false, + default: false + ) + return todo_database, todo_collection +end +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. + +```ruby +def seed_database(databases, todo_database, todo_collection) + test_todo1 = { + title: 'Buy apples', + description: 'At least 2KGs', + isComplete: true + } + + test_todo2 = { + title: 'Wash the apples', + isComplete: true + } + + test_todo3 = { + title: 'Cut the apples', + description: 'Don\'t forget to pack them in a box', + isComplete: false + } + + databases.create_document( + database_id: todo_database.id, + collection_id: todo_collection.id, + document_id: ID.unique(), + data: test_todo1 + ) + + databases.create_document( + database_id: todo_database.id, + collection_id: todo_collection.id, + document_id: ID.unique(), + data: test_todo2 + ) + + databases.create_document( + database_id: todo_database.id, + collection_id: todo_collection.id, + document_id: ID.unique(), + data: test_todo3 + ) +end +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +Create a function to retrieve the mock todo data and a function to execute the requests in order. +Run the functions to by calling `run_all_tasks()`. + +```ruby +def get_todos(databases, todo_database, todo_collection) + todos = databases.list_documents( + database_id: todo_database.id, + collection_id: todo_collection.id + ) + + todos.documents.each do |todo| + puts "Title: #{todo.data['title']}\nDescription: #{todo.data['description']}\nIs Todo Complete: #{todo.data['isComplete']}\n\n" + end +end + +def run_all_tasks(databases) + todo_database, todo_collection = prepare_database(databases) + seed_database(databases, todo_database, todo_collection) + get_todos(databases, todo_database, todo_collection) +end + +run_all_tasks(databases) +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with `ruby app.rb` and view the response in your console. + +{% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc new file mode 100644 index 0000000000..675a75c7cc --- /dev/null +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -0,0 +1,211 @@ +--- +layout: article +title: Start with Swift +description: Learn to get started with server integrations with Appwrite Swift SDK. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Swift project powered by Appwrite. + +{% info title="Server SDK" %} +This tutorial is for the Swift Server SDK, meant for server and backend applications. +If you're trying to build a client-side app, like an iOS, macOS, watchOS or tvOS app, +follow the [Start with Apple guide](https://appwrite.io/docs/quick-starts/apple). +{% /info %} + +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +If this is your first time using Appwrite, create an account and create your first project. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Server integrations](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Server integrations](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} +| Category {% width=120 %} | Required scopes | Purpose | +|-----------|-----------------------|---------| +| Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | +| | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | +| | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | + +Other scopes are optional. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +{% /section %} +{% section #step-2 step=2 title="Create Swift project" %} +Create a Swift CLI application by opening **XCode** > **Create a new XCode project** +> **macOS** > **Command Line Tool**. + +Follow the wizard and open your new project. + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Swift Appwrite SDK by going to **File** > **Add Packages...** and search for the repo url +`https://github.com/appwrite/sdk-for-swift` and select `sdk-for-swift`. + +{% /section %} +{% section #step-4 step=4 title="Import Appwrite" %} + +Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Open the file `main.swift` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```swift +import Foundation +import Appwrite +import AppwriteModels + +let client = Client() + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey("") +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```swift +let databases = Databases(client) + +func prepareDatabase() async -> (Database?, Collection?) { + let todoDatabase = try? await databases.create( + databaseId: ID.unique(), + name: "TodosDB" + ) + let todoCollection = try? await databases.createCollection( + databaseId: todoDatabase!.id, + collectionId: ID.unique(), + name: "Todos" + ) + try? await databases.createStringAttribute( + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, + key: "title", + size: 255, + xrequired: true + ) + try? await databases.createStringAttribute( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String, + key: "description", + size: 255, + xrequired: false, + xdefault: "This is a test description." + ) + try? await databases.createBooleanAttribute( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String, + key: "isComplete", + xrequired: true + ) + + return (todoDatabase, todoCollection) +} +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. +```swift +func seedDatabase(todoDatabase: Database?, todoCollection: Collection?) async { + let testTodo1: [String: Any] = [ + "title": "Buy apples", + "description": "At least 2KGs", + "isComplete": true + ] + + let testTodo2: [String: Any] = [ + "title": "Wash the apples", + "isComplete": true + ] + + let testTodo3: [String: Any] = [ + "title": "Cut the apples", + "description": "Don't forget to pack them in a box", + "isComplete": false + ] + + try? await databases.createDocument( + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, + documentId: ID.unique(), + data: testTodo1 + ) + try? await databases.createDocument( + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, + documentId: ID.unique(), + data: testTodo2 + ) + try? await databases.createDocument( + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, + documentId: ID.unique(), + data: testTodo3 + ) +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +Create a function to retrieve the mock todo data. + +```swift +func getTodos(todoDatabase: Database?, todoCollection: Collection?) async { + let todos = try? await databases.listDocuments( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String + ) + for document in todos?.documents ?? [] { + if let todo = document.data as? [String: Any] { + print("Title: \(todo["title"] ?? "")\n" + + "Description: \(todo["description"] ?? "")\n" + + "Is Todo Complete: \(todo["isComplete"] ?? "")\n\n" + ) + } + } +} + +let (todoDatabase, todoCollection) = await prepareDatabase() +await seedDatabase(todoDatabase: todoDatabase, todoCollection: todoCollection) +await getTodos(todoDatabase: todoDatabase, todoCollection: todoCollection) +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with XCode and see the results in the console. + +{% /section %} \ No newline at end of file