Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #396 from appwrite/add-dotnet-examples
Browse files Browse the repository at this point in the history
Add .NET SDK examples to guides
  • Loading branch information
christyjacob4 authored Jul 20, 2023
2 parents 60b3649 + 23f2a5d commit eb8eb60
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 1 deletion.
61 changes: 60 additions & 1 deletion app/views/docs/authentication-server.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ client
.setJWT("eyJJ9.eyJ...886ca") // Your secret JSON Web Token</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite;

var client = new Client();

client
.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.SetProject("[PROJECT_ID]") // Your project ID
.SetJWT("eyJJ9.eyJ...886ca"); // Your secret JSON Web Token</code></pre>
</div>
</li>
</ul>

<h2><a href="/docs/authentication-server#when-to-use" id="when-to-use">When Should I Use JWT Auth?</a></h2>
Expand Down Expand Up @@ -409,6 +422,29 @@ let documentList = try await databases.listDocuments(
/ ... More code to manipulate the results</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var client = new Client();

client
.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.SetProject("[PROJECT_ID]") // Your project ID
.SetJWT("eyJJ9.eyJ...886ca"); // Your secret JSON Web Token

var databases = new Databases(client);

var documentList = await databases.ListDocuments(
databaseId: "642f358bf4084c662590",
collectionId: "642f3592aa5fc856ad1e");

// ... More code to manipulate the results</code></pre>
</div>
</li>
</ul>

<p>Only the birthday of Kevin is returned and documents where <code>user-A</code> has no permissions to access are not returned.</p>
Expand Down Expand Up @@ -587,7 +623,30 @@ client
databaseId: "642f358bf4084c662590",
collectionId: "642f3592aa5fc856ad1e"
)
/ ... More code to manipulate the results</code></pre>
// ... More code to manipulate the results</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var client = new Client();

client
.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.SetProject("[PROJECT_ID]") // Your project ID
.SetKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

var databases = new Databases(client);

var documentList = await databases.ListDocuments(
databaseId: "642f358bf4084c662590",
collectionId: "642f3592aa5fc856ad1e");

// ... More code to manipulate the results</code></pre>
</div>
</li>
</ul>
Expand Down
23 changes: 23 additions & 0 deletions app/views/docs/databases-relationships.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,29 @@ databases.createRelationshipAttribute(
)</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite;
using Appwrite.Services;

var client = new Client()
.SetEndpoint("https://cloud.appwrite.io/v1")
.SetProject("[PROJECT_ID]");

var databases = new Databases(client);

await databases.CreateRelationshipAttribute(
databaseId: "marvel",
collectionId: "movies",
relatedCollectionId: "reviews",
type: "oneToMany",
twoWay: true,
key: "reviews",
twoWayKey: "movie",
onDelete: "cascade");</code></pre>
</div>
</li>
</ul>

<p>The above example adds a relationship between the collections <b>movies</b> and <b>reviews</b>. A relationship attribute with the key <code>reviews</code> is added to the movies collection and another relationship attribute with the key <code>movie</code> is added to the reviews collection.</p>
Expand Down
65 changes: 65 additions & 0 deletions app/views/docs/getting-started-for-server.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ $swiftVersion = $versions['swift'] ?? '';
]</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label="C#">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>dotnet add package Appwrite</code></pre>
</div>
</li>
</ul>

<h2><a href="/docs/getting-started-for-server#createProject" id="createProject">Create Your First Appwrite Project</a></h2>
Expand Down Expand Up @@ -216,6 +222,17 @@ let client = Client()
</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite;

var client = new Client()
.SetEndpoint("http://cloud.appwrite.io/v1") // Your Appwrite Endpoint
.SetProject("[PROJECT_ID]") // Your project ID
.SetKey("919c2db5d4...a2a3346ad2"); // Your secret API Key</code></pre>
</div>
</li>
</ul>

<div class="notice">
Expand Down Expand Up @@ -373,6 +390,18 @@ let client = Client()
.setEndpoint("https://cloud.appwrite.io/v1") // Your Appwrite Endpoint
.setProject("[PROJECT_ID]") // Your project ID
.setJWT("919c2db5d4...a2a3346ad2") // Your secret JWT
</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite;

var client = new Client()
.SetEndpoint("http://cloud.appwrite.io/v1") // Your Appwrite Endpoint
.SetProject("[PROJECT_ID]") // Your project ID
.SetJWT("919c2db5d4...a2a3346ad2"); // Your secret JWT
</code></pre>
</div>
</li>
Expand Down Expand Up @@ -521,6 +550,21 @@ let user = try await users.create(
)</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite.Services;
using Appwrite.Models;

var users = new Users(client);

var user = await users.Create(
userId: ID.Unique(),
email: "[email protected]",
phone: null,
password: "password");</code></pre>
</div>
</li>
</ul>

<h2><a href="/docs/getting-started-for-server#fullExample" id="fullExample">Full Example</a></h2>
Expand Down Expand Up @@ -711,6 +755,27 @@ let user = try await users.create(
)</code></pre>
</div>
</li>
<li>
<h3>.NET</h3>
<div class="ide margin-top-small" data-lang="csharp" data-lang-label=".NET SDK">
<pre class="line-numbers"><code class="prism language-csharp" data-prism>using Appwrite;
using Appwrite.Services;
using Appwrite.Models;

var client = new Client()
.SetEndpoint("http://cloud.appwrite.io/v1") // Your Appwrite Endpoint
.SetProject("[PROJECT_ID]") // Your project ID
.SetKey("cd868db89"); // Your secret API key

var users = new Users(client);

var user = await users.Create(
userId: ID.Unique(),
email: "[email protected]",
phone: null,
password: "password");</code></pre>
</div>
</li>
</ul>

<h2><a href="/docs/getting-started-for-server#nextSteps" id="nextSteps">Next Steps</a></h2>
Expand Down
27 changes: 27 additions & 0 deletions app/views/docs/storage.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,33 @@ File content.
</tr>
</tbody>
</table>
</li><li>
<h3>.NET</h3>
<p>
The Appwrite .NET SDK expects an <code>InputFile</code> class for file inputs.
</p>
<table class="full text-size-small">
<thead>
<tr>
<td style="width: 200px">Method</td>
<td>Description</td>
</tr>
</thead>
<tbody>
<tr>
<td><code>InputFile.FromPath(string path)</code></td>
<td>Used to upload files from a provided path.</td>
</tr>
<tr>
<td><code>InputFile.FromStream(Stream stream, string filename, string mimeType)</code></td>
<td>Used to upload files from a <a href="https://learn.microsoft.com/en-us/dotnet/api/system.io.stream?view=net-7.0" target="_blank" rel="noopener">Stream</a> object. Specify the file <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types" target="_blank" rel="noopener">MIME type</a> using the <code>mimeType</code> param.</td>
</tr>
<tr>
<td><code>InputFile.FromBytes(byte[] bytes, string filename, string mimeType)</code></td>
<td>Used to upload files from an array of bytes. Specify the file <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types" target="_blank" rel="noopener">MIME type</a> using the <code>mimeType</code> param.</td>
</tr>
</tbody>
</table>
</li>
</ul>

Expand Down

0 comments on commit eb8eb60

Please sign in to comment.