node-appwrite
Advanced tools
Comparing version
const Client = require('./lib/client.js'); | ||
const AppwriteException = require('./lib/exception.js'); | ||
const Avatars = require('./lib/services/avatars.js'); | ||
@@ -13,2 +14,3 @@ const Database = require('./lib/services/database.js'); | ||
Client, | ||
AppwriteException, | ||
Avatars, | ||
@@ -15,0 +17,0 @@ Database, |
const URL = require('url').URL; | ||
const axios = require('axios'); | ||
const FormData = require('form-data'); | ||
const AppwriteException = require('./exception.js'); | ||
@@ -11,3 +12,3 @@ class Client { | ||
'content-type': '', | ||
'x-sdk-version': 'appwrite:nodejs:2.0.0', | ||
'x-sdk-version': 'appwrite:nodejs:2.1.0', | ||
}; | ||
@@ -128,6 +129,16 @@ this.selfSigned = false; | ||
}; | ||
let response = await axios(options); | ||
return response.data; | ||
try { | ||
let response = await axios(options); | ||
return response.data; | ||
} catch(error) { | ||
if('response' in error) { | ||
if('data' in error.response) { | ||
throw new AppwriteException(error.response.data.message, error.response.status, error.response.data); | ||
}else{ | ||
throw new AppwriteException(error.response.statusText, error.response.status, error.response.data); | ||
} | ||
}else{ | ||
throw new AppwriteException(error.message); | ||
} | ||
} | ||
} | ||
@@ -134,0 +145,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"license": "BSD-3-Clause", | ||
@@ -15,5 +15,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"axios": "^0.20.0", | ||
"axios": "^0.21.1", | ||
"form-data": "^3.0.0" | ||
} | ||
} |
# Appwrite Node.js SDK | ||
 | ||
 | ||
 | ||
 | ||
[](https://twitter.com/appwrite_io) | ||
[](https://appwrite.io/discord) | ||
**This SDK is compatible with Appwrite server version 0.7.0. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).** | ||
**This SDK is compatible with Appwrite server version 0.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).** | ||
@@ -25,2 +27,65 @@ > This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code. | ||
## Getting Started | ||
### Init your SDK | ||
Initialize your SDK code with your project ID which can be found in your project settings page and your new API secret Key project API keys section. | ||
```js | ||
const sdk = require('node-appwrite'); | ||
let client = new sdk.Client(); | ||
client | ||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint | ||
.setProject('5df5acd0d48c2') // Your project ID | ||
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key | ||
; | ||
``` | ||
### 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 section. | ||
```js | ||
let users = new sdk.Users(client); | ||
let promise = users.create('email@example.com', 'password'); | ||
promise.then(function (response) { | ||
console.log(response); | ||
}, function (error) { | ||
console.log(error); | ||
}); | ||
``` | ||
### Full Example | ||
```js | ||
const sdk = require('node-appwrite'); | ||
let client = new sdk.Client(); | ||
client | ||
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint | ||
.setProject('5df5acd0d48c2') // Your project ID | ||
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key | ||
; | ||
let users = new sdk.Users(client); | ||
let promise = users.create('email@example.com', 'password'); | ||
promise.then(function (response) { | ||
console.log(response); | ||
}, function (error) { | ||
console.log(error); | ||
}); | ||
``` | ||
### Learn more | ||
You can use followng 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 Node Playground](https://github.com/appwrite/playground-for-node) | ||
## Contribution | ||
@@ -27,0 +92,0 @@ |
100421
3.34%93
2.2%1813
1.23%96
209.68%+ Added
- Removed
Updated