Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dotnet starter #30

Merged
merged 3 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
47 changes: 47 additions & 0 deletions dotnet/starter-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ⚡ .NET Starter Function
loks0n marked this conversation as resolved.
Show resolved Hide resolved

A simple starter function. Edit `src/Index.cs` to get started and create something awesome! 🚀

## 🧰 Usage

### `GET`

- Returns a "Hello, World!" message.

**Response**

Sample `200` Response:

```text
Hello, World! 🌎
```

### `POST`, `PUT`, `PATCH`, `DELETE`

- Returns a "Learn More" JSON response.

**Response**

Sample `200` Response:

```json
{
"motto": "Build Fast. Scale Big. All in One Place.",
"learn": "https://appwrite.io/docs",
"connect": "https://appwrite.io/discord",
"getInspired": "https://builtwith.appwrite.io"
}
```

## ⚙️ Configuration

| Setting | Value |
|-------------------|----------------|
| Runtime | dotnet (6.0) |
Meldiron marked this conversation as resolved.
Show resolved Hide resolved
| Entrypoint | `src/Index.cs` |
| Permissions | `any` |
| Timeout (Seconds) | 15 |

## 🔒 Environment Variables

No environment variables required.
8 changes: 8 additions & 0 deletions dotnet/starter-template/StarterTemplate.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
42 changes: 42 additions & 0 deletions dotnet/starter-template/src/Index.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace DotNetRuntime;

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

public class Handler {

// This is your Appwrite function
// It's executed each time we get a request
public async Task<RuntimeOutput> Main(RuntimeContext Context)
{
// Why not try the Appwrite SDK?
//
// var client = new Client()
// .SetEndpoint("http://cloud.appwrite.io/v1")
// .SetProject("5ff3379a01d25")
// .SetKey("cd868db89");
loks0n marked this conversation as resolved.
Show resolved Hide resolved

// You can log messages to the console
Context.Log('Hello, Logs! 👋');
loks0n marked this conversation as resolved.
Show resolved Hide resolved

// If something goes wrong, log an error
Context.Error('Hello, Errors! ⛔');

// The `Context.Req` object contains the request data
if (Context.Req.Method === 'GET') {
// Send a response with the res object helpers
// `Context.Res.Send()` dispatches a string back to the client
return Context.Req.Send('Hello, World! 🌎');
}

// `Context.Res.Json()` is a handy helper for sending JSON
return Context.Res.Json(new()
{
{ 'motto': 'Build Fast. Scale Big. All in One Place.' },
{ 'learn': 'https://appwrite.io/docs' },
{ 'connect': 'https://appwrite.io/discord' },
{ 'getInspired': 'https://builtwith.appwrite.io' },
});
}
}