Skip to content

Commit 619d2c9

Browse files
Merge pull request #300 from appwrite/feat-update-starters
Feat: Update starters
2 parents 7779c32 + 310a02e commit 619d2c9

File tree

35 files changed

+469
-411
lines changed

35 files changed

+469
-411
lines changed

_README_TEMPLATE.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@ Sample `400` Response:
4747

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

50-
| Setting | Value |
51-
| ----------------- | ---------------- |
52-
| Runtime | Node (18.0) |
53-
| Entrypoint | `src/main.js` |
54-
| Build Commands | `npm run build` |
55-
| Permissions | `any` |
56-
| Events | `users.*.create` |
57-
| CRON | `0 * * * *` |
58-
| Timeout (Seconds) | 15 |
50+
| Setting | Value |
51+
| ----------------- | -------------------------- |
52+
| Runtime | Node (18.0) |
53+
| Entrypoint | `src/main.js` |
54+
| Build Commands | `npm run build` |
55+
| Permissions | `any` |
56+
| Events | `users.*.create` |
57+
| CRON | `0 * * * *` |
58+
| Timeout (Seconds) | 15 |
59+
| Scopes | `teams.read`, `users.write`|
5960

6061
## 🔒 Environment Variables
6162

6263
<!-- Copy section for each variable -->
6364
<!-- Name the variable -->
6465

65-
### APPWRITE_API_KEY
66+
### GITHUB_ACCESS_TOKEN
6667

6768
<!-- Describe the variable -->
6869

69-
API Key to talk to Appwrite backend APIs.
70+
Access token to talk to GitHub APIs.
7071

7172
<!-- Mark if variable is required or not -->
7273
<!-- Provide sample (but invalid) value -->
@@ -76,4 +77,4 @@ API Key to talk to Appwrite backend APIs.
7677
| ------------- | ------------------------------------------------------------------------------------------- |
7778
| Required | Yes / No |
7879
| Sample Value | `d1efb...aec35` |
79-
| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/advanced/platform/api-keys) |
80+
| Documentation | [GitHub: Access tokens](https://github.com/settings/tokens) |

bun/starter/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ A simple starter function. Edit `src/main.ts` to get started and create somethin
44

55
## 🧰 Usage
66

7-
### GET /
7+
### GET /ping
88

9-
- Returns a "Hello, World!" message.
9+
- Returns a "Pong" message.
1010

1111
**Response**
1212

1313
Sample `200` Response:
1414

1515
```text
16-
Hello, World!
16+
Pong
1717
```
1818

19-
### POST, PUT, PATCH, DELETE /
19+
### GET, POST, PUT, PATCH, DELETE /
2020

2121
- Returns a "Learn More" JSON response.
2222

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

4647
## 🔒 Environment Variables
4748

bun/starter/env.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare module "bun" {
2+
interface Env {
3+
APPWRITE_FUNCTION_API_ENDPOINT: string;
4+
APPWRITE_FUNCTION_PROJECT_ID: string;
5+
}
6+
}
7+
8+
export {};

bun/starter/src/main.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
import { Client } from "node-appwrite";
1+
import { Client, Users } from "node-appwrite";
22

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

13-
// You can log messages to the console
14-
log("Hello, Logs!");
15-
16-
// If something goes wrong, log an error
17-
error("Hello, Errors!");
13+
try {
14+
const response = await users.list();
15+
// Log messages and errors to the Appwrite Console
16+
// These logs won't be seen by your end users
17+
log(`Total users: ${response.total}`);
18+
} catch(err) {
19+
error("Could not list users: " + err.message);
20+
}
1821

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

26-
// `res.json()` is a handy helper for sending JSON
2729
return res.json({
2830
motto: "Build like a team of hundreds_",
2931
learn: "https://appwrite.io/docs",

cpp/starter/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ A simple starter function. Edit `src/main.cc` to get started and create somethin
44

55
## 🧰 Usage
66

7-
### GET /
7+
### GET /ping
88

9-
- Returns a "Hello, World!" message.
9+
- Returns a "Pong" message.
1010

1111
**Response**
1212

1313
Sample `200` Response:
1414

1515
```text
16-
Hello, World!
16+
Pong
1717
```
1818

19-
### POST, PUT, PATCH, DELETE /
19+
### GET, POST, PUT, PATCH, DELETE /
2020

2121
- Returns a "Learn More" JSON response.
2222

cpp/starter/src/main.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@
66
namespace runtime {
77
class Handler {
88
public:
9-
// This is your Appwrite function
10-
// It's executed each time we get a request
9+
// This Appwrite function will be executed every time your function is triggered
1110
static RuntimeOutput main(RuntimeContext &context) {
12-
// You can log messages to the console
11+
// Log messages and errors to the Appwrite Console
12+
// These logs won't be seen by your end users
1313
context.log("Hello, Logs!");
14-
15-
// If something goes wrong, log an error
1614
context.error("Hello, Errors!");
1715

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

25-
// `context.res.json()` is a handy helper for sending JSON
2623
Json::Value response;
2724
response["motto"] = "Build like a team of hundreds_";
2825
response["learn"] = "https://appwrite.io/docs";

dart/starter/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ A simple starter function. Edit `lib/main.dart` to get started and create someth
44

55
## 🧰 Usage
66

7-
### GET /
7+
### GET /ping
88

9-
- Returns a "Hello, World!" message.
9+
- Returns a "Pong" message.
1010

1111
**Response**
1212

1313
Sample `200` Response:
1414

1515
```text
16-
Hello, World!
16+
Pong
1717
```
1818

19-
### POST, PUT, PATCH, DELETE /
19+
### GET, POST, PUT, PATCH, DELETE /
2020

2121
- Returns a "Learn More" JSON response.
2222

dart/starter/lib/main.dart

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
import 'dart:async';
2+
import 'dart:io';
23
import 'package:dart_appwrite/dart_appwrite.dart';
34

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

14-
// You can log messages to the console
15-
context.log('Hello, Logs!');
16-
17-
// If something goes wrong, log an error
18-
context.error('Hello, Errors!');
15+
try {
16+
final response = await users.list();
17+
// Log messages and errors to the Appwrite Console
18+
// These logs won't be seen by your end users
19+
context.log('Total users: ' + response.total.toString());
20+
} catch (e) {
21+
context.error('Could not list users: ' + e.toString());
22+
}
1923

20-
// The `req` object contains the request data
21-
if (context.req.method == 'GET') {
22-
// Send a response with the res object helpers
23-
// `res.send()` dispatches a string back to the client
24-
return context.res.send('Hello, World!');
24+
// The req object contains the request data
25+
if (context.req.path == "/ping") {
26+
// Use res object to respond with text(), json(), or binary()
27+
// Don't forget to return a response!
28+
return context.res.text('Pong');
2529
}
2630

27-
// `res.json()` is a handy helper for sending JSON
2831
return context.res.json({
2932
'motto': 'Build like a team of hundreds_',
3033
'learn': 'https://appwrite.io/docs',

deno/starter/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ A simple starter function. Edit `src/main.ts` to get started and create somethin
44

55
## 🧰 Usage
66

7-
### GET /
7+
### GET /ping
88

9-
- Returns a "Hello, World!" message.
9+
- Returns a "Pong" message.
1010

1111
**Response**
1212

1313
Sample `200` Response:
1414

1515
```text
16-
Hello, World!
16+
Pong
1717
```
1818

19-
### POST, PUT, PATCH, DELETE /
19+
### GET, POST, PUT, PATCH, DELETE /
2020

2121
- Returns a "Learn More" JSON response.
2222

deno/starter/src/main.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
import { Client } from "https://deno.land/x/[email protected]/mod.ts";
1+
import { Client, Users } from "https://deno.land/x/[email protected]/mod.ts";
22

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

13-
// You can log messages to the console
14-
log("Hello, Logs!");
15-
16-
// If something goes wrong, log an error
17-
error("Hello, Errors!");
13+
try {
14+
const response = await users.list();
15+
// Log messages and errors to the Appwrite Console
16+
// These logs won't be seen by your end users
17+
log(`Total users: ${response.total}`);
18+
} catch(err) {
19+
error("Could not list users: " + err.message);
20+
}
1821

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

26-
// `res.json()` is a handy helper for sending JSON
2729
return res.json({
2830
motto: "Build like a team of hundreds_",
2931
learn: "https://appwrite.io/docs",

0 commit comments

Comments
 (0)