You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-web/releases).**
9
+
**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-web/releases).**
10
10
11
11
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Web SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
For you to init your SDK and interact with Appwrite services you need to add a web platform to your project. To add a new platform, go to your Appwrite console, choose the project you created in the step before and click the 'Add Platform' button.
44
45
45
46
From the options, choose to add a **Web** platform and add your client app hostname. By adding your hostname to your project platform you are allowing cross-domain communication between your project and the Appwrite API.
46
47
47
48
### Init your SDK
49
+
48
50
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page.
49
51
50
52
```js
@@ -58,6 +60,7 @@ client
58
60
```
59
61
60
62
### Make Your First Request
63
+
61
64
Once your SDK object is set, access any of the Appwrite services 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.
The Appwrite Web SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a generic type parameter that allows you to specify your custom model type for full type safety.
console.log(`Book: ${book.name} by ${book.author}`); // Now you have full type safety
126
+
});
127
+
} catch (error) {
128
+
console.error('Appwrite error:', error);
129
+
}
130
+
```
131
+
132
+
**JavaScript (with JSDoc for type hints):**
133
+
```javascript
134
+
/**
135
+
* @typedef{Object}Book
136
+
* @property{string}name
137
+
* @property{string}author
138
+
* @property{string}[releaseYear]
139
+
* @property{string}[category]
140
+
* @property{string[]}[genre]
141
+
* @property{boolean}isCheckedOut
142
+
*/
143
+
144
+
constdatabases=newDatabases(client);
145
+
146
+
try {
147
+
/**@type{Models.DocumentList<Book>}*/
148
+
constdocuments=awaitdatabases.listDocuments(
149
+
'your-database-id',
150
+
'your-collection-id'
151
+
);
152
+
153
+
documents.documents.forEach(book=> {
154
+
console.log(`Book: ${book.name} by ${book.author}`); // Type hints available in IDE
155
+
});
156
+
} catch (error) {
157
+
console.error('Appwrite error:', error);
158
+
}
159
+
```
160
+
161
+
**Tip**: You can use the `appwrite types` command to automatically generate TypeScript interfaces based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation).
162
+
163
+
### Error Handling
164
+
165
+
The Appwrite Web SDK raises an `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching the exception and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.
0 commit comments