Skip to content

Latest commit

 

History

History
149 lines (107 loc) · 4.34 KB

File metadata and controls

149 lines (107 loc) · 4.34 KB

Appwrite C++ SDK

C++ Appwrite GitHub License Version

banner-appwrite

Overview

This C++ SDK is built from scratch as a prototype for interacting with Appwrite's backend services.

  • It allows users to perform a limited set of functionalities as of now,
  • including the creation of databases, collections, and documents,
  • while also enabling the retrieval of usage statistics and
  • management of storage and account health.

This SDK is compatible with Appwrite server version 1.6.x.

Appwrite

Installation (Linux)

Prerequisites

Before you begin, ensure conan, clang-format, and cmake are installed:

sudo apt install clang-format cmake
pip install conan

Build From Source Code

Clone the repository and run the following commands (out-of-source build, all artifacts in build/ only):

mkdir build && cd build
conan install .. --output-folder=. --build=missing
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
make

All Conan and CMake files will be in build/.

Install the SDK.

sudo make install

Installation (Windows)

Prerequisites

  • Install MinGW-w64 and add it to your system PATH.
  • Install Conan using Python/pip.
  • Install CMake.

Build From Source Code

  1. Open a MinGW-w64 environment or Command Prompt with MinGW in PATH.
  2. Clone the repository and run:
mkdir build
cd build
conan install .. --output-folder=. --build=missing
cmake .. -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
mingw64-make

Install SDK (MinGW)

To copy the headers and library to your MinGW installation, use: ./install_windows.bat

This will place headers in <MinGW Root>\include\AppwriteSDK and library files in <MinGW Root>\lib.

Getting Started

Make Your First Request

Set the neccessary header files.

#include "AppwriteSDK/Appwrite.hpp"

Once your SDK header is set, create the Appwrite service objects and choose the request to send.

    std::string projectId = "<your-project-id>";
    std::string apiKey = "<your-api-key>"; 

    Appwrite appwrite(projectId, apiKey);

    // for the Databases instance
    Databases& databases = appwrite.getDatabases();

Full Example

#include "Appwrite.hpp"
#include <iostream>

int main() {
    std::string projectId = "<your-project-id>";
    std::string apiKey = "<your-api-key>"; 
    std::string databaseId = "<unique-database-id>";
    std::string name = "<unique-database-name>";
    bool enabled = true;

    Appwrite appwrite(projectId, apiKey);
    
    std::string response = appwrite.getDatabases().create(databaseId, name, enabled);

    return 0;
}    

Error Handling

The Appwrite C++ SDK raises AppwriteException object with message, code and response properties. You can handle any errors by catching AppwriteException and present the message to the user or handle it yourself based on the provided error information. Below is an example.

    try {
        // Send some request here
    } catch (const AppwriteException& ex) {
        std::cerr << "Exception: " << ex.what() << std::endl;
    }

Compilation & Execution

  • Compile

g++ -o <output-file-name> <your-file-name>.cpp -I/usr/local/include/AppwriteSDK -L/usr/local/lib -lAppwriteSDK -lcurl
  • Execute

./output-file-name

For a more detailed view of the implementations, please check out the example directory. Example

Learn more

You can use the following resources to learn more and get help

License

This project is licensed under the MIT License, and further details can be found in the LICENSE file.