#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 feat…


This content originally appeared on DEV Community and was authored by Christy Jacob

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
  • Windows
$ iwr -useb https://appwrite.io/cli/install.ps1 | iex

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

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"

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

$ appwrite [SERVICE] [COMMAND] --[OPTIONS]

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   ║
╚═══════════════╧══════╝

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 

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 : {}

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{}    ║
╚═══════════════╧═════════════════╧══════════════╧════════╧════════════════════╧═══════════════════╧═══════╝

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

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 ?


This content originally appeared on DEV Community and was authored by Christy Jacob


Print Share Comment Cite Upload Translate Updates
APA

Christy Jacob | Sciencx (2021-05-22T13:21:07+00:00) #30DaysOfAppwrite : Appwrite CLI. Retrieved from https://www.scien.cx/2021/05/22/30daysofappwrite-appwrite-cli/

MLA
" » #30DaysOfAppwrite : Appwrite CLI." Christy Jacob | Sciencx - Saturday May 22, 2021, https://www.scien.cx/2021/05/22/30daysofappwrite-appwrite-cli/
HARVARD
Christy Jacob | Sciencx Saturday May 22, 2021 » #30DaysOfAppwrite : Appwrite CLI., viewed ,<https://www.scien.cx/2021/05/22/30daysofappwrite-appwrite-cli/>
VANCOUVER
Christy Jacob | Sciencx - » #30DaysOfAppwrite : Appwrite CLI. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/22/30daysofappwrite-appwrite-cli/
CHICAGO
" » #30DaysOfAppwrite : Appwrite CLI." Christy Jacob | Sciencx - Accessed . https://www.scien.cx/2021/05/22/30daysofappwrite-appwrite-cli/
IEEE
" » #30DaysOfAppwrite : Appwrite CLI." Christy Jacob | Sciencx [Online]. Available: https://www.scien.cx/2021/05/22/30daysofappwrite-appwrite-cli/. [Accessed: ]
rf:citation
» #30DaysOfAppwrite : Appwrite CLI | Christy Jacob | Sciencx | https://www.scien.cx/2021/05/22/30daysofappwrite-appwrite-cli/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.