DEV Community

Cover image for #30DaysOfAppwrite : Appwrite CLI
Christy Jacob for Appwrite

Posted on

#30DaysOfAppwrite : Appwrite CLI

Intro

#30DaysOfAppwrite is a month long event focused at 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 22 ๐Ÿ‘‹. For a really long time, we found ourselves having to set up an SDK to quickly test some new functionality, so we decided to build ourselves a CLI! We wanted to stay agnostic to the technology used so we decided to go with a Docker approach. Appwrite CLI is packaged as a Docker container, so the only dependency you will ever need is Docker ๐Ÿ˜Š. 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 with the convenience of using your terminal. You can even use it to automate tasks on your CI pipeline. Here's an article by Torsten about how you can use the CLI to automate function deployments in your CI.

Installation

If you already have Docker installed, you can follow along. Otherwise, you will need to first install Docker for your platform by following the instructions here. Once you have Docker installed, installing the CLI should be a breeze ๐ŸŒฌ

  • MacOS and Linux
$ curl -sL https://appwrite.io/cli/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
  • Windows
$ iwr -useb https://appwrite.io/cli/install.ps1 | iex
Enter fullscreen mode Exit fullscreen mode

You should be greeted with a slick install shield and if everything goes well, you should see a message from Obi-Wan Kenobi himself.

CLI Install Shield

Great, you can then verify your install using

$ appwrite version 
CLI Version : 0.0.1
Server Version : 0.8.0
Enter fullscreen mode Exit fullscreen mode

To communicate with your Appwrite server, you will need to first initialize your CLI using the appwrite init command. You will have to enter your endpoint, projectID, API key and locale, so keep these handy. Our API key needs the following scopes to run the example commands below:

  • users.read
  • users.write
  • locale.read

Appwrite CLI Init

If you plan to use the CLI in a CI pipeline, you can use the non-interactive version of the init command like so

$ appwrite init --project="PROJECT_ID" \ 
                --endpoint="http://localhost/v1" \ 
                --key="PROJECT_KEY" \
                --locale="en-US"
Enter fullscreen mode Exit fullscreen mode

Before we start executing some commands, let's get familiar with the syntax of a command.

$ appwrite [SERVICE] [COMMAND] --[OPTIONS]
Enter fullscreen mode Exit fullscreen mode

You can see a list of all the services that Appwrite offers using the appwrite help command

Appwrite Help

Let's make a request to the Locale service

$ appwrite locale getContinents
sum : 7
continents :
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•—
โ•‘ Name          โ”‚ Code โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ Africa        โ”‚ AF   โ•‘
โ•‘ Antarctica    โ”‚ AN   โ•‘
โ•‘ Asia          โ”‚ AS   โ•‘
โ•‘ Europe        โ”‚ EU   โ•‘
โ•‘ North America โ”‚ NA   โ•‘
โ•‘ Oceania       โ”‚ OC   โ•‘
โ•‘ South America โ”‚ SA   โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•
Enter fullscreen mode Exit fullscreen mode

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 setSelfSigned --value=true 
Enter fullscreen mode Exit fullscreen mode

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 setup the Server Side SDK to make this request. With the CLI, you can simply use the appwrite users create command.

$  appwrite users create --email="chris@hemsworth.com" --password="very_strong_password" --name="Chris Hemsworth"
$id : 60a2b0c66148c
name : Chris Hemsworth
registration : 1621274822
status : 0
email : chris@hemsworth.com
emailVerification : false
prefs : {}
Enter fullscreen mode Exit fullscreen mode

You can list your users using

$ appwrite users list
sum : 1
users :
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•คโ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ $id           โ”‚ Name            โ”‚ Registration โ”‚ Status โ”‚ Email              โ”‚ EmailVerification โ”‚ Prefs โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ 60a2b0c66148c โ”‚ Chris Hemsworth โ”‚ 1621274822   โ”‚ 0      โ”‚ chris@hemsworth... โ”‚ false             โ”‚ {}    โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•
Enter fullscreen mode Exit fullscreen mode

If you ever get stuck with the usage of a particular command, you can always use the help command like so

$ appwrite users help
$ appwrite database help
Enter fullscreen mode Exit fullscreen mode

Appwrite Users 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 ๐Ÿ‘‹

Discussion (0)