GitHub - appwrite/sdk-for-dotnet: [READ-ONLY] Official Appwrite .NET SDK · GitHub
Skip to content

About

[READ-ONLY] Official Appwrite .NET SDK

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

128 stars

Watchers

13 watching

Forks

Appwrite .NET SDK

License Version X Account Discord

This SDK targets Appwrite server version 2.5.x as shipped on Appwrite Cloud. Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from previous releases when APIs differ.

Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the .NET SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to https://appwrite.io/docs

Installation

The package targets .NET Standard 2.0 and .NET Framework 4.6.2, so it runs on .NET 5 or later, .NET Core 2.0 or later, and .NET Framework 4.6.2 or later.

Install it with the .NET CLI:

dotnet add package Appwrite --version 11.0.0

Or with the Package Manager Console:

Install-Package Appwrite -Version 11.0.0

Or add a reference to your project's .csproj file:

<PackageReference Include="Appwrite" Version="11.0.0" />

Getting Started

Initialize and make an API request

Initialize the SDK with your Appwrite endpoint, project ID, and an API key. Find the endpoint and project ID in your project's Settings page, and create an API key with the scopes your code needs under Overview > Integrations > API keys. API keys grant server-level access, so keep them out of client-side code.

using Appwrite;
using Appwrite.Services;

var client = new Client()
    .SetEndpoint("https://<REGION>.cloud.appwrite.io/v1")
    .SetProject("<PROJECT_ID>")
    .SetKey("<API_KEY>");

var users = new Users(client);

var user = await users.Create(
    userId: ID.Unique(),
    email: "email@example.com",
    password: "password",
    name: "Walter O'Brien");

Console.WriteLine(user.Name);

If you self-host Appwrite, use your own endpoint, such as https://appwrite.example.com/v1. During local development with a self-signed certificate, call .SetSelfSigned(true) to skip certificate verification. Never use it in production.

Error handling

The SDK throws an AppwriteException when a request fails. It exposes Message, Code, Type, and Response properties that you can use to inspect the error.

try
{
    var user = await users.Create(
        userId: ID.Unique(),
        email: "email@example.com",
        password: "password",
        name: "Walter O'Brien");
}
catch (AppwriteException e)
{
    Console.WriteLine(e.Message);
}

Preparing models for TablesDB

The SDK serializes request data with System.Text.Json and converts property names from PascalCase to camelCase. If your table's column names are not in camelCase, the serialized names will not match your columns.

Add the JsonPropertyName attribute to each property of your model so it serializes to the column name. For example, for a table with a name column (string) and a release_date column (datetime):

using System.Text.Json.Serialization;

public class Movie
{
    [JsonPropertyName("name")]
    public string Name { get; set; }

    [JsonPropertyName("release_date")]
    public DateTime ReleaseDate { get; set; }
}

Pass the model as the row data:

var tablesDB = new TablesDB(client);

var row = await tablesDB.CreateRow(
    databaseId: "<DATABASE_ID>",
    tableId: "<TABLE_ID>",
    rowId: ID.Unique(),
    data: new Movie { Name = "Spider-Man", ReleaseDate = new DateTime(2002, 5, 3) });

Learn more

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

Contribution

This library is auto-generated by Appwrite custom SDK Generator. To learn more about how you can help us improve this SDK, please check the contribution guide before sending a pull-request.

License

Please see the BSD-3-Clause license file for more information.

About

[READ-ONLY] Official Appwrite .NET SDK

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

128 stars

Watchers

13 watching

Forks

Releases

Used by

Contributors

Languages