DEV Community

Cover image for Announcing Appwrite’s New .NET SDK
Aditya Oberai for Appwrite

Posted on • Edited on

Announcing Appwrite’s New .NET SDK

With the launch of Appwrite 1.4, we're excited to share that we now have a .NET SDK available to build with Appwrite. This is a server-side SDK that targets .NET Standard 2.0, supporting a wide range of SDK versions across .NET, .NET Core, and .NET Framework.

Steps to Install

Currently, the SDK is distributed through the NuGet Package Manager.

You can use the Command Line to install the package in your project using the following commands:

# Package Manager

Install-Package Appwrite -Version 0.5.0

# or .NET CLI

dotnet add package Appwrite --version 0.5.0
Enter fullscreen mode Exit fullscreen mode

Please make sure to add a reference to the package in your project’s .csproj file, if it isn’t present already.

<PackageReference Include="Appwrite" Version="0.5.0" />
Enter fullscreen mode Exit fullscreen mode

Getting Started with the SDK

Initializing the SDK

Once you have installed the package, you can import the package in your code and set your Appwrite credentials to start making API calls.

using Appwrite;

var client = new Client()
    .SetEndpoint("https://cloud.appwrite.io/v1")
    .SetProject("5ff3379a01d25")
    .SetKey("cd868db89");
Enter fullscreen mode Exit fullscreen mode

Consuming Appwrite Services

Once your SDK is initialized, you can start consuming the various APIs offered by Appwrite. Here are some examples:

Create a User

using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var users = new Users(client);
var user = await users.Create(
    userId: ID.Unique(),
    email: "[email protected]",
    password: "password",
    name: "name");
Enter fullscreen mode Exit fullscreen mode

Add a Document To Your Database Collection

using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var databases = new Databases(client);
var document = await databases.CreateDocument(
    databaseId: "[DATABASE_ID]",
    collectionId: "[COLLECTION_ID]",
    documentId: "[DOCUMENT_ID]",
    data: [object]);
Enter fullscreen mode Exit fullscreen mode

Upload a File

using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var storage = new Storage(client);
var file = await storage.CreateFile(
    bucketId: "[BUCKET_ID]",
    fileId: "[FILE_ID]",
    file: new File("./path-to-files/image.jpg"));
Enter fullscreen mode Exit fullscreen mode

Trigger a Function Execution

using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var functions = new Functions(client);
var execution = await functions.CreateExecution(
      functionId: "[FUNCTION_ID]",
      body: "[REQUEST_BODY]",
      method: "POST",
      path: "/");
Enter fullscreen mode Exit fullscreen mode

Error Handling

The Appwrite .NET SDK throws an AppwriteException object, which includes Message, Code, and Response properties. You can handle any errors by catching AppwriteException and presenting the Message to the user or using the error types provided by Appwrite to decide the right type of error and display custom error messages. Below is an example:

using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var users = new Users(client);
try
{
    var user = await users.Create(
        userId: ID.Unique(),
        email: "[email protected]",
        password: "password",
        name: "name");
}
catch (AppwriteException e)
{
    Console.WriteLine(e.Message);
}
Enter fullscreen mode Exit fullscreen mode

How to Contribute and Share Feedback

In case you discover any bugs/issues, want to share suggestions, or make contributions to the .NET SDK, please visit Appwrite’s SDK Generator repository on GitHub.

All contributions, including those by people with commit access, must go through a pull request and be approved by an Appwrite core team member before merging. This is to ensure a proper review of all the contributions. You can learn more by visiting the repo’s Contribution Guide.

Next Steps

We hope you will try the .NET SDK in your upcoming projects and share any thoughts and concerns you have with us. Here are some resources you can use to learn more about Appwrite and start building projects:

Top comments (4)

Collapse
 
bonglv profile image
Ly Van Bong

Hope you will have more Client SDKs .net version

Collapse
 
adityaoberai profile image
Aditya Oberai

We have thought about creating SDKs for different .NET based client-side frameworks. If you have any frameworks you'd like SDKs for, do share your thoughts here.

Collapse
 
tessamero profile image
Tessa Mero

Nice work! Way to go Team Appwrite <3

Collapse
 
adityaoberai profile image
Aditya Oberai

Aye aye 🥳