Intro
#30DaysOfAppwrite is a month-long event focused on giving developers a walk-through of all of Appwrite's features, starting from the basics to more advanced features like Cloud Functions! Alongside we will also be building a fully-featured Medium clone to demonstrate how these
concepts can be applied when building a real-world app. We also have some exciting prizes for developers who follow along with us!
Appwrite CLI
Welcome to Day 21 π. For a really long time, we found ourselves needing to set up an SDK to test new functionalities quickly, so we decided to build ourselves a CLI! The CLI is packaged both as an npm module and a standalone binary for your operating system, making it completely dependency-free, platform independent, and language agnostic. The CLI is generated automatically using our Swagger specification and our very own SDK generator.
Appwrite CLI features all the powerful features of the server-side SDKs and more with the convenience of using your terminal. You can even use it to automate tasks on your CI pipeline. The Appwrite CLI can be used to deploy and manage functions and collections specified in a config file called appwrite.json
. The config file allows you to use the Appwrite CLI to replicate collection and function setups across Appwrite instances quickly!
Installation
- Install with NPM
npm install -g appwrite-cli
Install from Binary
Windows
iwr -useb https://appwrite.io/cli/install.ps1 | iex
- Mac OS
Install using Homebrew:
brew tap appwrite/sdk-for-cli https://github.com/appwrite/sdk-for-cli
brew update
brew install --HEAD appwrite
Install using cURL:
curl -sL https://appwrite.io/cli/install.sh | bash
- Linux
Install using cURL:
curl -sL https://appwrite.io/cli/install.sh | bash
- Verify Your Installation
You should see your Appwrite CLI's version number if you run:
appwrite -v
Initializing Your CLI
To communicate with your Appwrite server, you will need first to initialize your CLI. The CLI needs to know which Appwrite instance it must point to, so we first pass in your Appwrite instance's endpoint:
appwrite client --endpoint "http://<API endpoint>/v1"
After providing your Appwrite CLI with an endpoint, you can log in to your Appwrite server by running:
appwrite login
Finally, we need to point the CLI to an Appwrite project, so navigate to an empty directory. You can initialize the project with the following commands:
# This command is interactive
appwrite init project
Ensure to select the project we have been working on for 30 Days of Appwrite. Remember and note down the directory. We will be using it in the coming days.
Trying the CLI
Let's make a request to the Locale Service:
appwrite locale getContinents
Which will output the following:
total : 7
continents
name β code
ββββββββββββββββΌββββββ
Africa β AF
ββββββββββββββββΌββββββ
Antarctica β AN
ββββββββββββββββΌββββββ
Asia β AS
ββββββββββββββββΌββββββ
Europe β EU
ββββββββββββββββΌββββββ
North America β NA
ββββββββββββββββΌββββββ
Oceania β OC
ββββββββββββββββΌββββββ
South America β SA
β Success
You might experience an SSL error in case you are trying to connect to a domain without a valid SSL certificate. By default, requests to domains with self-signed SSL certificates (or no certificates) are disabled. If you trust the domain, you can bypass the certificate validation by using.
appwrite client --selfSigned true
Great, now let's try executing a command that has some parameters. Let's say you want to create a new user in your project. Prior to the CLI, you would have to set up the server-side SDK to make this request. With the CLI, you can use the appwrite users create
command.
appwrite users create --userId 'unique()' --email "chris@hemsworth.com" --password "very_strong_password" --name="Chris Hemsworth"
Which will output the following:
$id : 6255c478548f6ec74c6b
name : Chris Hemsworth
registration : 1649788024
status : true
passwordUpdate : 1649788024
email : chris@hemsworth.com
emailVerification : false
prefs
β Success
You can list your users using.
appwrite users list
Which will output the following:
total : 1
users
$id β name β registration β status β passwordUpdate β email β emailVerification β prefs
βββββββββββββββββββββββΌββββββββββββββββββΌβββββββββββββββΌβββββββββΌβββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββ
6255c478548f6ec74c6b β Chris Hemsworth β 1649788024 β true β 1649788024 β chris@hemsworth.com β false β object
β Success
If you ever get stuck with the usage of a particular command, you can always use the help
command like this:
appwrite users help
appwrite database help
In the upcoming session, we will talk about Cloud Functions and highlight how the CLI can be used to easily create, package and deploy cloud functions without ever leaving your console!
Credits
We hope you liked this write-up. You can follow #30DaysOfAppwrite on Social Media to keep up with all of our posts. The complete event timeline can be found here
Feel free to reach out to us on Discord if you would like to learn more about Appwrite, Aliens or Unicorns π¦. Stay tuned for tomorrow's article! Until then π
Top comments (0)