Skip to content

Commit

Permalink
Merge pull request #300 from appwrite/feat-update-starters
Browse files Browse the repository at this point in the history
Feat: Update starters
  • Loading branch information
christyjacob4 authored Aug 8, 2024
2 parents 7779c32 + 310a02e commit 619d2c9
Show file tree
Hide file tree
Showing 35 changed files with 469 additions and 411 deletions.
25 changes: 13 additions & 12 deletions _README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,27 @@ Sample `400` Response:

<!-- Update values and remove irrelevant settings -->

| Setting | Value |
| ----------------- | ---------------- |
| Runtime | Node (18.0) |
| Entrypoint | `src/main.js` |
| Build Commands | `npm run build` |
| Permissions | `any` |
| Events | `users.*.create` |
| CRON | `0 * * * *` |
| Timeout (Seconds) | 15 |
| Setting | Value |
| ----------------- | -------------------------- |
| Runtime | Node (18.0) |
| Entrypoint | `src/main.js` |
| Build Commands | `npm run build` |
| Permissions | `any` |
| Events | `users.*.create` |
| CRON | `0 * * * *` |
| Timeout (Seconds) | 15 |
| Scopes | `teams.read`, `users.write`|

## 🔒 Environment Variables

<!-- Copy section for each variable -->
<!-- Name the variable -->

### APPWRITE_API_KEY
### GITHUB_ACCESS_TOKEN

<!-- Describe the variable -->

API Key to talk to Appwrite backend APIs.
Access token to talk to GitHub APIs.

<!-- Mark if variable is required or not -->
<!-- Provide sample (but invalid) value -->
Expand All @@ -76,4 +77,4 @@ API Key to talk to Appwrite backend APIs.
| ------------- | ------------------------------------------------------------------------------------------- |
| Required | Yes / No |
| Sample Value | `d1efb...aec35` |
| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/advanced/platform/api-keys) |
| Documentation | [GitHub: Access tokens](https://github.com/settings/tokens) |
9 changes: 5 additions & 4 deletions bun/starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ A simple starter function. Edit `src/main.ts` to get started and create somethin

## 🧰 Usage

### GET /
### GET /ping

- Returns a "Hello, World!" message.
- Returns a "Pong" message.

**Response**

Sample `200` Response:

```text
Hello, World!
Pong
```

### POST, PUT, PATCH, DELETE /
### GET, POST, PUT, PATCH, DELETE /

- Returns a "Learn More" JSON response.

Expand All @@ -42,6 +42,7 @@ Sample `200` Response:
| Build Commands | `bun install` |
| Permissions | `any` |
| Timeout (Seconds) | 15 |
| Scopes | `users.read` |

## 🔒 Environment Variables

Expand Down
8 changes: 8 additions & 0 deletions bun/starter/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module "bun" {
interface Env {
APPWRITE_FUNCTION_API_ENDPOINT: string;
APPWRITE_FUNCTION_PROJECT_ID: string;
}
}

export {};
42 changes: 22 additions & 20 deletions bun/starter/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { Client } from "node-appwrite";
import { Client, Users } from "node-appwrite";

// This is your Appwrite function
// It's executed each time we get a request
// This Appwrite function will be executed every time your function is triggered
export default async ({ req, res, log, error }: any) => {
// Why not try the Appwrite SDK?
//
// const client = new Client()
// .setEndpoint('https://cloud.appwrite.io/v1')
// .setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
// .setKey(Bun.env["APPWRITE_API_KEY"]);
// You can use the Appwrite SDK to interact with other services
// For this example, we're using the Users service
const client = new Client()
.setEndpoint(Bun.env["APPWRITE_FUNCTION_API_ENDPOINT"])
.setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
.setKey(req.headers['x-appwrite-key'] ?? '');
const users = new Users(client);

// You can log messages to the console
log("Hello, Logs!");

// If something goes wrong, log an error
error("Hello, Errors!");
try {
const response = await users.list();
// Log messages and errors to the Appwrite Console
// These logs won't be seen by your end users
log(`Total users: ${response.total}`);
} catch(err) {
error("Could not list users: " + err.message);
}

// The `req` object contains the request data
if (req.method === "GET") {
// Send a response with the res object helpers
// `res.send()` dispatches a string back to the client
return res.send("Hello, World!");
// The req object contains the request data
if (req.path === "/ping") {
// Use res object to respond with text(), json(), or binary()
// Don't forget to return a response!
return res.text("Pong");
}

// `res.json()` is a handy helper for sending JSON
return res.json({
motto: "Build like a team of hundreds_",
learn: "https://appwrite.io/docs",
Expand Down
8 changes: 4 additions & 4 deletions cpp/starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ A simple starter function. Edit `src/main.cc` to get started and create somethin

## 🧰 Usage

### GET /
### GET /ping

- Returns a "Hello, World!" message.
- Returns a "Pong" message.

**Response**

Sample `200` Response:

```text
Hello, World!
Pong
```

### POST, PUT, PATCH, DELETE /
### GET, POST, PUT, PATCH, DELETE /

- Returns a "Learn More" JSON response.

Expand Down
19 changes: 8 additions & 11 deletions cpp/starter/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
namespace runtime {
class Handler {
public:
// This is your Appwrite function
// It's executed each time we get a request
// This Appwrite function will be executed every time your function is triggered
static RuntimeOutput main(RuntimeContext &context) {
// You can log messages to the console
// Log messages and errors to the Appwrite Console
// These logs won't be seen by your end users
context.log("Hello, Logs!");

// If something goes wrong, log an error
context.error("Hello, Errors!");

// The `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.res.send("Hello, World!");
// The req object contains the request data
if (context.req.path == "/ping") {
// Use res object to respond with text(), json(), or binary()
// Don't forget to return a response!
return context.res.text("Pong");
}

// `context.res.json()` is a handy helper for sending JSON
Json::Value response;
response["motto"] = "Build like a team of hundreds_";
response["learn"] = "https://appwrite.io/docs";
Expand Down
8 changes: 4 additions & 4 deletions dart/starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ A simple starter function. Edit `lib/main.dart` to get started and create someth

## 🧰 Usage

### GET /
### GET /ping

- Returns a "Hello, World!" message.
- Returns a "Pong" message.

**Response**

Sample `200` Response:

```text
Hello, World!
Pong
```

### POST, PUT, PATCH, DELETE /
### GET, POST, PUT, PATCH, DELETE /

- Returns a "Learn More" JSON response.

Expand Down
41 changes: 22 additions & 19 deletions dart/starter/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import 'dart:async';
import 'dart:io';
import 'package:dart_appwrite/dart_appwrite.dart';

// This is your Appwrite function
// It's executed each time we get a request
// This Appwrite function will be executed every time your function is triggered
Future<dynamic> main(final context) async {
// Why not try the Appwrite SDK?
//
// final client = Client()
// .setEndpoint('https://cloud.appwrite.io/v1')
// .setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'])
// .setKey(Platform.environment['APPWRITE_API_KEY']);
// You can use the Appwrite SDK to interact with other services
// For this example, we're using the Users service
final client = Client()
.setEndpoint(Platform.environment['APPWRITE_FUNCTION_API_ENDPOINT'] ?? '')
.setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'] ?? '')
.setKey(context.req.headers['x-appwrite-key'] ?? '');
final users = Users(client);

// You can log messages to the console
context.log('Hello, Logs!');

// If something goes wrong, log an error
context.error('Hello, Errors!');
try {
final response = await users.list();
// Log messages and errors to the Appwrite Console
// These logs won't be seen by your end users
context.log('Total users: ' + response.total.toString());
} catch (e) {
context.error('Could not list users: ' + e.toString());
}

// The `req` object contains the request data
if (context.req.method == 'GET') {
// Send a response with the res object helpers
// `res.send()` dispatches a string back to the client
return context.res.send('Hello, World!');
// The req object contains the request data
if (context.req.path == "/ping") {
// Use res object to respond with text(), json(), or binary()
// Don't forget to return a response!
return context.res.text('Pong');
}

// `res.json()` is a handy helper for sending JSON
return context.res.json({
'motto': 'Build like a team of hundreds_',
'learn': 'https://appwrite.io/docs',
Expand Down
8 changes: 4 additions & 4 deletions deno/starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ A simple starter function. Edit `src/main.ts` to get started and create somethin

## 🧰 Usage

### GET /
### GET /ping

- Returns a "Hello, World!" message.
- Returns a "Pong" message.

**Response**

Sample `200` Response:

```text
Hello, World!
Pong
```

### POST, PUT, PATCH, DELETE /
### GET, POST, PUT, PATCH, DELETE /

- Returns a "Learn More" JSON response.

Expand Down
42 changes: 22 additions & 20 deletions deno/starter/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { Client } from "https://deno.land/x/[email protected]/mod.ts";
import { Client, Users } from "https://deno.land/x/[email protected]/mod.ts";

// This is your Appwrite function
// It's executed each time we get a request
// This Appwrite function will be executed every time your function is triggered
export default async ({ req, res, log, error }: any) => {
// Why not try the Appwrite SDK?
//
// const client = new Client()
// .setEndpoint('https://cloud.appwrite.io/v1')
// .setProject(Deno.env.get("APPWRITE_FUNCTION_PROJECT_ID"))
// .setKey(Deno.env.get("APPWRITE_API_KEY"));
// You can use the Appwrite SDK to interact with other services
// For this example, we're using the Users service
const client = new Client()
.setEndpoint(Deno.env.get("APPWRITE_FUNCTION_API_ENDPOINT") ?? '')
.setProject(Deno.env.get("APPWRITE_FUNCTION_PROJECT_ID") ?? '')
.setKey(req.headers['x-appwrite-key'] ?? '');
const users = new Users(client);

// You can log messages to the console
log("Hello, Logs!");

// If something goes wrong, log an error
error("Hello, Errors!");
try {
const response = await users.list();
// Log messages and errors to the Appwrite Console
// These logs won't be seen by your end users
log(`Total users: ${response.total}`);
} catch(err) {
error("Could not list users: " + err.message);
}

// The `req` object contains the request data
if (req.method === "GET") {
// Send a response with the res object helpers
// `res.send()` dispatches a string back to the client
return res.send("Hello, World!");
// The req object contains the request data
if (req.path === "/ping") {
// Use res object to respond with text(), json(), or binary()
// Don't forget to return a response!
return res.text("Pong");
}

// `res.json()` is a handy helper for sending JSON
return res.json({
motto: "Build like a team of hundreds_",
learn: "https://appwrite.io/docs",
Expand Down
8 changes: 4 additions & 4 deletions dotnet/starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ A simple starter function. Edit `src/Index.cs` to get started and create somethi

## 🧰 Usage

### GET /
### GET /ping

- Returns a "Hello, World!" message.
- Returns a "Pong" message.

**Response**

Sample `200` Response:

```text
Hello, World!
Pong
```

### POST, PUT, PATCH, DELETE /
### GET, POST, PUT, PATCH, DELETE /

- Returns a "Learn More" JSON response.

Expand Down
Loading

0 comments on commit 619d2c9

Please sign in to comment.