Skip to content

Commit

Permalink
Merge pull request #28 from appwrite/feat-cpp-starter
Browse files Browse the repository at this point in the history
feat: C++ starter
  • Loading branch information
Meldiron authored Jul 22, 2023
2 parents 4655a7e + 62ffef8 commit ab41c96
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
47 changes: 47 additions & 0 deletions cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ⚑ C++ Starter Function

A simple starter function. Edit `src/main.cc` 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 | C++ (17) |
| Entrypoint | `src/main.cc` |
| Permissions | `any` |
| Timeout (Seconds) | 15 |

## πŸ”’ Environment Variables

No environment variables required.
29 changes: 29 additions & 0 deletions cpp/src/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace runtime {
class Handler {
public:
// This is your Appwrite function
// It's executed each time we get a request
static RuntimeOutput main(RuntimeContext &context) {
// You can log messages to the console
context.log("Hello, Logs! πŸ‘‹");

// If something goes wrong, log an error
context.log("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! 🌎");
}

// `context.res.json()` is a handy helper for sending JSON
Json::Value response;
response['motto'] = "Build Fast. Scale Big. All in One Place.";
response['learn'] = "https://appwrite.io/docs";
response['connect'] = "https://appwrite.io/discord";
response['getInspired'] = "https://builtwith.appwrite.io";
return context.res.json(response);
}
};
}

0 comments on commit ab41c96

Please sign in to comment.