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: Java starter #25

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 29 additions & 0 deletions java/starter-template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
47 changes: 47 additions & 0 deletions java/starter-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ⚡ Java Starter Function

A simple starter function. Edit `src/Main.java` 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 | Java (17) |
| Entrypoint | `src/Main.java` |
| Permissions | `any` |
| Timeout (Seconds) | 15 |

## 🔒 Environment Variables

No environment variables required.
3 changes: 3 additions & 0 deletions java/starter-template/deps.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
implementation 'io.appwrite:sdk-for-kotlin:2.0.0'
}
40 changes: 40 additions & 0 deletions java/starter-template/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.HashMap;
import io.appwrite.Client;

public class Main {

// This is your Appwrite function
// It's executed each time we get a request
public RuntimeOutput main(RuntimeContext context) throws Exception {
// Why not try the Appwrite SDK?
//
// Client client = new Client();
// client
// .setEndpoint("https://cloud.appwrite.io/v1")
// .setProject(System.getenv("APPWRITE_PROJECT_ID"))
// .setKey(System.getenv("APPWRITE_API_KEY"));

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

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

// The `context.getReq()` object contains the request data
if (context.getReq().getMethod().equals("GET")) {
// Send a response with the res object helpers
// `context.getRes().send()` dispatches a string back to the client
return context.getRes().send("Hello, World! 🌎");
}

// `context.getRes().json()` is a handy helper for sending JSON
return context.getRes().json(new HashMap<String, String>() {
{
put("motto", "Build Fast. Scale Big. All in One Place.");
put("learn", "https://appwrite.io/docs");
put("connect", "https://appwrite.io/discord");
put("getInspired", "https://builtwith.appwrite.io");
}
});
}
}