This repository contains the source to both the Client and Server .net implimentation for Appwrite API. This is not a first party SDK, rather a third party SDK.
This is a work in progress. There are 2 SDK's - one for client and another for server.
It is recommended to install just the client SDK into client-side projects, and both the client and server SDK into server side projects.
Install-Package PinguApps.Appwrite.Client
or in the Nuget package manager, search for PinguApps.Appwrite.Client
(ensure you are searching for prerelease versions)
Install-Package PinguApps.Appwrite.Server
or in the Nuget package manager, search for PinguApps.Appwrite.Server
Once the package(s) are installed, you will need to add everything to your DI container. Thankfully, there's an extension method making this simple.
There are 2 extension methods for the client SDK. One intended for client side usage, and the other for server side usage. The only difference is the lifetimes used in the DI container.
For client side:
services.AddAppwriteClient("Project_Id");
For Server side:
services.AddAppwriteClientForServer("Project_Id");
This will assume that you are using Appwrite in the cloud. If you are not, then you can specify your endpoint as the second parameter, which is optional. Additionally, for finer control, you can specify your own
RefitSettings
as the third parameter.
services.AddAppwriteServer("Project_Id", "Api_Key");
This will assume that you are using Appwrite in the cloud. If you are not, then you can specify your endpoint as the second parameter, which is optional. Additionally, for finer control, you can specify your own
RefitSettings
as the third parameter.
To inject the SDK, you will need to request either an IAppwriteClient
or IAppwriteServer
, depending on which you are working with and need.
public class App
{
private readonly IAppwriteClient _client;
private readonly IAppwriteServer _server;
public App(IAppwriteClient client, IAppwriteServer server)
{
_client = client;
_server = server;
}
}
The Client SDK will manage sessions for you. You can set the current session with:
_client.SetSession("SessionToken");
Both SDK's are split up into sections, matching the Appwrite Docs.
To make a call to get the current logged in account on the client SDK, you can do this with:
var user = await _client.Account.Get();
To create an account with the Server SDK, it might look like this:
var request = new CreateAccountRequest
{
Email = "[email protected]",
Password = "MySuperSecretPassword",
Name = "Pingu"
};
var user = await _server.Account.Create(request);
The result object is made up of a Result
property, as well as some bool
's to assist in determining the success or failure. The Result
Property will be one of 3 different types, depending on what happened.
All following examples will be based on the following preceeding them:
var userResponse = await _client.Account.Get();
We can determine if the call we made was successful or not by checking userResponse.Success
. If this is true, the Result
will be an object of the type returned from the API, in this case it will be of type User
.
If userResponse.Success
is false, then userResponse.IsError
will be true (which we could also use to check the inverse).
If we have errored, then there might be 2 sources for the error. One would be Appwrite throwing an error, and the other would be internal - within the SDK. This could be a bug with the SDK, or invalid input provided to it.
If userResponse.IsAppwriteError
is true, then Result
will be of type AppwriteError
.
If userResponse.IsInternalError
is true, then Result
will be of type InternalError
.
We can switch on the result type, allowing us to perform different logic based on the success status.
userResponse.Result.Switch(
account => Console.WriteLine(account.Email),
appwriteError => Console.WriteLine(appwriteError.Message),
internalError => Console.WriteLine(internalError.Message)
);
We can also pull out the known type of the response:
if(userResponse.Success)
{
var email = userResponse.Result.AsT0.Email;
}
Finally, we can return something different depending on what type it is:
string emailAddressOrErrorMessage = userResponse.Result.Match(
account => account.Email,
appwriteError => appwriteError.Message,
internalError => internalError.Message
);
Icon | Definition |
---|---|
✅ | The endpoint is implemented for the given SDK type (client or server) |
⬛ | The endpoint is not yet implemented for the given SDK type (client or server), but will be |
❌ | There is currently no intention to implement the endpoint for the given SDK type (client or server) |
Endpoint | Client | Server |
---|---|---|
List Teams | ✅ | ✅ |
Create Team | ✅ | ✅ |
Get Team | ✅ | ✅ |
Update Name | ✅ | ✅ |
Delete Team | ✅ | ✅ |
List Team Memberships | ✅ | ✅ |
Create Team Membership | ✅ | ✅ |
Get Team Membership | ✅ | ✅ |
Update Membership | ✅ | ✅ |
Delete Team Membership | ✅ | ✅ |
Update Team Membership Status | ✅ | ❌ |
Get Team Memberships | ✅ | ✅ |
Update Preferences | ✅ | ✅ |
Endpoint | Client | Server |
---|---|---|
List Buckets | ❌ | ⬛ |
Create Bucket | ❌ | ⬛ |
Get Bucket | ❌ | ⬛ |
Update Bucket | ❌ | ⬛ |
Delete Bucket | ❌ | ⬛ |
List Files | ⬛ | ⬛ |
Create File | ⬛ | ⬛ |
Get File | ⬛ | ⬛ |
Update File | ⬛ | ⬛ |
Delete File | ⬛ | ⬛ |
Get File For Download | ⬛ | ⬛ |
Get File Preview | ⬛ | ⬛ |
Get File For View | ⬛ | ⬛ |
Endpoint | Client | Server |
---|---|---|
List Functions | ❌ | ⬛ |
Create Function | ❌ | ⬛ |
List Runtimes | ❌ | ⬛ |
Get Function | ❌ | ⬛ |
Update Function | ❌ | ⬛ |
Delete Function | ❌ | ⬛ |
List Deployments | ❌ | ⬛ |
Create Deployment | ❌ | ⬛ |
Get Deployment | ❌ | ⬛ |
Update Function Deployment | ❌ | ⬛ |
Delete Deployment | ❌ | ⬛ |
Create Build | ❌ | ⬛ |
Download Deployment | ❌ | ⬛ |
List Executions | ⬛ | ⬛ |
Create Execution | ⬛ | ⬛ |
Get Execution | ⬛ | ⬛ |
List Variables | ❌ | ⬛ |
Create Variable | ❌ | ⬛ |
Get Variable | ❌ | ⬛ |
Update Variable | ❌ | ⬛ |
Delete Variable | ❌ | ⬛ |
Endpoint | Client | Server |
---|---|---|
Get User Locale | ⬛ | ❌ |
List Locale Codes | ⬛ | ⬛ |
List Continents | ⬛ | ⬛ |
List Countries | ⬛ | ⬛ |
List EU Countries | ⬛ | ⬛ |
List Countries Phone Codes | ⬛ | ⬛ |
List Currencies | ⬛ | ⬛ |
List Languages | ⬛ | ⬛ |
Endpoint | Client | Server |
---|---|---|
Get Browser Icon | ⬛ | ⬛ |
Get Credit Card Icon | ⬛ | ⬛ |
Get Favicon | ⬛ | ⬛ |
Get Country Flag | ⬛ | ⬛ |
Get Image From Url | ⬛ | ⬛ |
Get Initials | ⬛ | ⬛ |
Get QR Code | ⬛ | ⬛ |
Endpoint | Client | Server |
---|---|---|
Get HTTP | ❌ | ⬛ |
Get Antivirus | ❌ | ⬛ |
Get Cache | ❌ | ⬛ |
Get the SSL certificate for a domain | ❌ | ⬛ |
Get DB | ❌ | ⬛ |
Get PubSub | ❌ | ⬛ |
Get Queue | ❌ | ⬛ |
Get Builds Queue | ❌ | ⬛ |
Get Certificates Queue | ❌ | ⬛ |
Get Databases Queue | ❌ | ⬛ |
Get Deletes Queue | ❌ | ⬛ |
Get Number of Failed Jobs | ❌ | ⬛ |
Get Functions Queue | ❌ | ⬛ |
Get Logs Queue | ❌ | ⬛ |
Get Mails Queue | ❌ | ⬛ |
Get Messaging Queue | ❌ | ⬛ |
Get Migrations Queue | ❌ | ⬛ |
Get Usage Queue | ❌ | ⬛ |
Get Usage Dump Queue | ❌ | ⬛ |
Get Webhooks Queue | ❌ | ⬛ |
Get Storage | ❌ | ⬛ |
Get Local Storage | ❌ | ⬛ |
Get Time | ❌ | ⬛ |