Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 22, 2021 01:21 pm GMT

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
  • 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.1Server 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 getContinentssum : 7continents : 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="[email protected]" --password="very_strong_password" --name="Chris Hemsworth"$id : 60a2b0c66148cname : Chris Hemsworthregistration : 1621274822status : 0email : [email protected] : falseprefs : {}

You can list your users using

$ appwrite users listsum : 1users : $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


Original Link: https://dev.to/appwrite/30daysofappwrite-appwrite-cli-2mde

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To