Getting Started for Server
Appwrite is a development platform that provides a powerful API and management console to get your next project up and running quickly.
This tutorial helps you start using Appwrite with your project. Before starting, make sure you have followed the Appwrite installation guide, and you have an Appwrite server instance up and running on your host machine or server.
Get the Appwrite SDK for Your Platform
We provide libraries and SDKs for major programming languages and platforms so you don't have to write code for interacting with our HTTP APIs from scratch.
Choose your desired SDK corresponding to your product development platform and import it using the given package manager. For the sake of this tutorial we use code examples using Appwrite SDKs for Node.js, PHP, Python, Ruby, Dart, and Deno, but the same can be applied to any of our server side SDKs.
-
Node.js
npm install node-appwrite --save
-
PHP
composer require 'appwrite/appwrite'
-
Python
pip install appwrite
-
Ruby
gem install appwrite
-
Deno
import * as sdk from "https://deno.land/x/appwrite/mod.ts";
-
Dart
dart pub add dart_appwrite
-
Kotlin
Add maven repositories to your build.gradle(.kts) file
repositories { mavenCentral() }
Add Appwrite SDK under dependencies in your build.gradle(.kts) file
dependencies { implementation("io.appwrite:sdk-for-kotlin:1.2.0") }
-
Swift
Add the Appwrite Swift SDK package as a dependency
dependencies: [ .package( name: "Appwrite", url: "https://github.com/appwrite/sdk-for-swift.git", .exact("1.2.0") ) ]
Add the dependency product to your target
dependencies: [ "Appwrite" ]
Create Your First Appwrite Project
Go to your new Appwrite console and click the icon in the top navigation header or on the 'Create Project' button on your console homepage. Choose a name for your project and click create to get started.
Authentication
The Appwrite server API provides you with two authentication methods. The first one uses an API key, and the second is using a JSON Web Token (JWT). Each method has different use cases, and you can use whichever fills your app needs.
API Key
Using an API Key you can interact with the Appwrite server API as an admin. You'll be able to access all of your project resources as long as your key has the relevant access scopes attached. To get your first API key, go to your appwrite console, choose the project you created in the step before and click the 'API Keys' link.
Inside your API keys screen, click the 'Add API Key' button, choose your key name, for example: 'Demo Key', and select the scopes your key are granted to use. After complete, you could copy your new API Key and use it to initialize your Appwrite server SDK. To learn about the different API scopes available to you, read more about Appwrite API Keys
-
Node.js
const { Client } = require('node-appwrite'); const client = new Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setKey('919c2db5d4...a2a3346ad2'); // Your secret API key
-
PHP
use Appwrite\Client; $client = (new Client()) ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint ->setProject('5df5acd0d48c2') // Your project ID ->setKey('919c2db5d4...a2a3346ad2'); // Your secret API key
-
Python
from appwrite.client import Client client = (Client() .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint .set_project('5df5acd0d48c2') # Your project ID .set_key('919c2db5d4...a2a3346ad2')) # Your secret API key
-
Ruby
require 'appwrite' client = Appwrite::Client.new() .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint .set_project('5df5acd0d48c2') # Your project ID .set_key('919c2db5d4...a2a3346ad2') # Your secret API key
-
Deno
import { Client } from "https://deno.land/x/appwrite/mod.ts"; const client = new Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setKey('919c2db5d4...a2a3346ad2'); // Your secret API key
-
Dart
import 'package:dart_appwrite/dart_appwrite.dart'; Client client = Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setKey('919c2db5d4...a2a3346ad2'); // Your secret API key
-
Kotlin
import io.appwrite.Client val client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID .setKey("919c2db5d4...a2a3346ad2") // Your secret API key
-
Swift
import Appwrite let client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID .setKey("919c2db5d4...a2a3346ad2") // Your secret API key
API Key Authentication
When using Server SDKs, you authenticate with API keys. API keys are not restricted by account-based permissions but have restrictions on the types of resources that can be accessed. This means API keys can access all resources of specified types, regardless of which account can access them.
JSON Web Token (JWT) version >= 0.8
Using a JSON Web Token (JWT), you can interact with the Appwrite server API as a specific user. You'll be able to access only the relevant user resources and perform actions on his behalf.
To create a JWT, you need to use the "account->createJWT" method using one of the Appwrite client SDKs. Before creating a token, you need to make sure your user is authenticated using the createSession method or log in with an OAuth provider.
-
Web SDK
const account = new Account(client); account.createJWT() .then(function (response) { console.log(response); }, function (error) { console.log(error); });
-
Flutter SDK
Account account = Account(client); Response user = await account.createJWT();
-
Android SDK
val account = Account(client) val response = account.createJWT()
-
Apple SDK
let account = Account(client) let response = try await account.createJWT()
After you get your valid token, you can pass it to your server and use it to initialize your Appwrite Server SDK and start making API calls. Your JWT is valid for a maximum time of 15 minutes or less if the user session has expired before that time.
-
Node.js
const { Client } = require('node-appwrite'); const client = new Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setJWT('919c2db5d4...a2a3346ad2'); // Your secret JWT
-
PHP
use Appwrite\Client; $client = (new Client()) ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint ->setProject('5df5acd0d48c2') // Your project ID ->setJWT('919c2db5d4...a2a3346ad2'); // Your secret JWT
-
Python
from appwrite.client import Client client = (Client() .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint .set_project('5df5acd0d48c2') # Your project ID .set_key('919c2db5d4...a2a3346ad2') # Your secret JWT )
-
Ruby
require 'appwrite' client = Client.new() .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint .set_project('5df5acd0d48c2') # Your project ID .set_key('919c2db5d4...a2a3346ad2') # Your secret JWT
-
Deno
import { Client } from "https://deno.land/x/appwrite/mod.ts"; const client = new Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setJWT('919c2db5d4...a2a3346ad2'); // Your secret JWT
-
Dart
import 'package:dart_appwrite/dart_appwrite.dart'; Client client = Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setJWT('919c2db5d4...a2a3346ad2'); // Your secret JWT
-
Kotlin
import io.appwrite.Client val client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID .setJWT("919c2db5d4...a2a3346ad2") // Your secret JWT
-
Swift
import Appwrite let client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID .setJWT("919c2db5d4...a2a3346ad2") // Your secret JWT
Make Your First Request
After your SDK configuration 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 section.
-
Node.js
const { ID, Users } = require('node-appwrite'); const users = new Users(client); let promise = users.create( ID.unique(), 'email@example.com', null, 'password' ); promise.then(function (response) { console.log(response); }, function (error) { console.log(error); });
-
PHP
use Appwrite\ID; use Appwrite\Services\Users; $users = new Users($client); $user = $users->create( userId: ID::unique(), email: 'email@example.com', phone: null, password: 'password' );
-
Python
from appwrite.id import ID from appwrite.services.users import Users users = Users(client) user = users.create( user_id=ID.unique(), email='email@example.com', phone=None, password='password' )
-
Ruby
require 'appwrite' users = Appwrite::Users.new(client) user = users.create( userId: ID.unique(), email: 'email@example.com', phone: nil, password: 'password' )
-
Deno
import { ID, Users } from "https://deno.land/x/appwrite/mod.ts"; const users = new Users(client); let promise = users.create( ID.unique(), 'email@example.com', null, 'password' ); promise.then(function (response) { console.log(response); }, function (error) { console.log(error); });
-
Dart
import 'package:dart_appwrite/dart_appwrite.dart'; final users = Users(client); final user = await users.create( userId: ID.unique(), email: 'email@example.com', phone: null, password: 'password' );
-
Kotlin
import io.appwrite.ID import io.appwrite.services.Users val users = Users(client) val user = users.create( userId = ID.unique(), email = 'email@example.com', phone = null, password = 'password' )
-
Swift
import Appwrite import AppwriteModels let users = Users(client) let user = try await users.create( userId: ID.unique(), email: "email@example.com", phone: nil, password: "password" )
Full Example
-
Node.js
const { Client, ID, Users } = require('node-appwrite'); const client = new Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setKey('919c2db5d4...a2a3346ad2'); // Your secret API key const users = new Users(client); let promise = users.create( ID.unique(), 'email@example.com', null, 'password' ); promise.then(function (response) { console.log(response); }, function (error) { console.log(error); });
-
PHP
use Appwrite\Client; use Appwrite\ID; use Appwrite\Services\Users; $client = (new Client()) ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint ->setProject('5df5acd0d48c2') // Your project ID ->setKey('919c2db5d4...a2a3346ad2'); // Your secret API key $users = new Users($client); $user = $users->create( userId: ID::unique(), email: 'email@example.com', phone: null, password: 'password' );
-
Python
from appwrite.client import Client from appwrite.id import ID from appwrite.services.users import Users client = (Client() .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint .set_project('5df5acd0d48c2') # Your project ID .set_key('919c2db5d4...a2a3346ad2')) # Your secret API key users = Users(client) user = users.create( user_id=ID.unique(), email='email@example.com', phone=None, password='password' )
-
Ruby
require 'appwrite' include Appwrite client = Client.new() .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint .set_project('5df5acd0d48c2') # Your project ID .set_key('919c2db5d4...a2a3346ad2') # Your secret API key users = Users.new(client) user = users.create( userId: ID.unique(), email: 'email@example.com', phone: nil, password: 'password' )
-
Deno
import { Client, ID, Users } from "https://deno.land/x/appwrite/mod.ts"; const client = new Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setKey('919c2db5d4...a2a3346ad2') // Your secret API key const users = new Users(client); let promise = users.create( ID.unique(), 'email@example.com', null, 'password' ); promise.then(function (response) { console.log(response); }, function (error) { console.log(error); });
-
Dart
import 'package:dart_appwrite/dart_appwrite.dart'; final client = Client() .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID .setKey('919c2db5d4...a2a3346ad2'); // Your secret API key final users = Users(client); final user = await users.create( userId: ID.unique(), email: 'email@example.com', phone: null, password: 'password' );
-
Kotlin
import io.appwrite.Client import io.appwrite.ID import io.appwrite.services.Users val client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID .setKey("919c2db5d4...a2a3346ad2") // Your secret API key val users = Users(client) val user = users.create( userId = ID.unique(), email = 'email@example.com', phone = null, password = 'password' )
-
Swift
import Appwrite import AppwriteModels let client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID .setKey("919c2db5d4...a2a3346ad2") // Your secret API key let users = Users(client) let user = try await users.create( userId: ID.unique(), email: "email@example.com", phone: nil, password: "password" )
Next Steps
Appwrite has many services and tools to help improve your app and speed up your development. The best way to learn how you can take advantage of them is to explore the different API references docs.
-