diff --git a/java/starter-template/.gitignore b/java/starter-template/.gitignore new file mode 100644 index 00000000..3904a570 --- /dev/null +++ b/java/starter-template/.gitignore @@ -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 diff --git a/java/starter-template/README.md b/java/starter-template/README.md new file mode 100644 index 00000000..b75c5210 --- /dev/null +++ b/java/starter-template/README.md @@ -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. diff --git a/java/starter-template/deps.gradle b/java/starter-template/deps.gradle new file mode 100644 index 00000000..6bd8824c --- /dev/null +++ b/java/starter-template/deps.gradle @@ -0,0 +1,3 @@ +dependencies { + implementation 'io.appwrite:sdk-for-kotlin:2.0.0' +} \ No newline at end of file diff --git a/java/starter-template/src/Main.java b/java/starter-template/src/Main.java new file mode 100644 index 00000000..c0525080 --- /dev/null +++ b/java/starter-template/src/Main.java @@ -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() { + { + 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"); + } + }); + } +} \ No newline at end of file