### Basic Restate HTTP Server Setup with Vert.x Source: https://github.com/restatedev/documentation/blob/main/static/javadocs/dev/restate/sdk/http/vertx/RestateHttpServer.html This example demonstrates the basic setup for a Restate HTTP server using Vert.x. It shows how to build an endpoint, bind a service to it, and then start listening for requests. ```java public static void main(String[] args) { Endpoint endpoint = Endpoint.builder() .bind(new Counter()) .build(); RestateHttpServer.listen(endpoint); } ``` -------------------------------- ### Setup Python Virtual Environment and Install Dependencies Source: https://github.com/restatedev/documentation/blob/main/code_snippets/python/README.md Use these commands to create a virtual environment, activate it, and install project dependencies from a requirements file. ```shell python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Get Greeter Service Template (Vanilla Gradle, CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Fetches the Kotlin Hello World Gradle example using the Restate CLI. ```shell restate example kotlin-hello-world-gradle && cd kotlin-hello-world-gradle ``` -------------------------------- ### Get Started with Deno+Restate Template Source: https://github.com/restatedev/documentation/blob/main/docs/deploy/services/faas/deno-deploy.md Use this command to quickly set up a new Deno project with Restate pre-configured. ```shell restate example typescript-deno-hello-world && cd typescript-deno-hello-world ``` -------------------------------- ### Get Java Hello World (Maven/Quarkus) via wget Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Java Hello World example using Maven and Quarkus via wget. ```shell wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-maven-quarkus.zip && ``` -------------------------------- ### Get Greeter Service Template (Vanilla Gradle, wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Fetches the Kotlin Hello World Gradle example by downloading and unzipping a zip archive. ```shell wget https://github.com/restatedev/examples/releases/latest/download/kotlin-hello-world-gradle.zip && unzip kotlin-hello-world-gradle.zip -d kotlin-hello-world-gradle && rm kotlin-hello-world-gradle.zip && cd kotlin-hello-world-gradle ``` -------------------------------- ### Install Restate Server and CLI via Homebrew Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Install the Restate Server and CLI using Homebrew. After installation, start the Restate Server. ```shell brew install restatedev/tap/restate-server restatedev/tap/restate ``` ```shell restate-server ``` -------------------------------- ### Get Java Hello World (Maven/Quarkus) via CLI Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Java Hello World example using Maven and Quarkus via the Restate CLI. ```shell restate example java-hello-world-maven-quarkus && cd java-hello-world-maven-quarkus ``` -------------------------------- ### Get Greeter Service Template (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Fetches the Kotlin Hello World Spring Boot example by downloading and unzipping a zip archive. ```shell wget https://github.com/restatedev/examples/releases/latest/download/kotlin-hello-world-gradle-spring-boot.zip && unzip kotlin-hello-world-gradle-spring-boot.zip -d kotlin-hello-world-gradle-spring-boot && rm kotlin-hello-world-gradle-spring-boot.zip && cd kotlin-hello-world-gradle-spring-boot ``` -------------------------------- ### Get Greeter Service Template (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Fetches the Kotlin Hello World Spring Boot example using the Restate CLI. ```shell restate example kotlin-hello-world-gradle-spring-boot && cd kotlin-hello-world-gradle-spring-boot ``` -------------------------------- ### Download Example Project Source: https://github.com/restatedev/documentation/blob/main/docs/guides/cron.mdx Download and navigate to the example project directory for TypeScript, Java, or Go. ```shell restate example typescript-patterns-use-cases && cd typescript-patterns-use-cases ``` ```shell restate example java-patterns-use-cases && cd java-patterns-use-cases ``` ```shell restate example go-patterns-use-cases && cd go-patterns-use-cases ``` -------------------------------- ### Download and Run Go Example (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Use the Restate CLI to download and navigate to the Go tour example. ```shell restate example go-tour-of-restate && cd go-tour-of-restate ``` -------------------------------- ### Download Example Code Source: https://github.com/restatedev/documentation/blob/main/docs/guides/sagas.mdx Download and navigate to the example project directory for your chosen SDK. ```shell restate example typescript-patterns-use-cases && cd typescript-patterns-use-cases ``` ```shell restate example java-patterns-use-cases && cd java-patterns-use-cases ``` ```shell restate example kotlin-patterns-use-cases && cd kotlin-patterns-use-cases ``` ```shell restate example python-patterns-use-cases && cd python-patterns-use-cases ``` ```shell restate example go-patterns-use-cases && cd go-patterns-use-cases ``` -------------------------------- ### Download and Run Go Example (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Download the Go tour example using wget, unzip it, and navigate to the directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/go-tour-of-restate.zip && unzip go-tour-of-restate.zip -d go-tour-of-restate && rm go-tour-of-restate.zip && cd go-tour-of-restate ``` -------------------------------- ### Get Rust Greeter service template (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Rust Greeter service example as a zip archive, extracts it, and navigates into the project directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/rust-hello-world.zip && unzip rust-hello-world.zip -d rust-hello-world && rm rust-hello-world.zip && cd rust-hello-world ``` -------------------------------- ### Get Java Hello World (Maven/Spring) via wget Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Java Hello World example using Maven and Spring Boot via wget. ```shell wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-maven-spring-boot.zip && unzip java-hello-world-maven-spring-boot.zip -d java-hello-world-maven-spring-boot && rm java-hello-world-maven-spring-boot.zip && cd java-hello-world-maven-spring-boot ``` -------------------------------- ### Download and Run Java Example (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Download the Java tour example using wget, unzip it, and navigate to the directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/java-tour-of-restate.zip && unzip java-tour-of-restate.zip -d java-tour-of-restate && rm java-tour-of-restate.zip && cd java-tour-of-restate ``` -------------------------------- ### Download and Run Java Example (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Use the Restate CLI to download and navigate to the Java tour example. ```shell restate example java-tour-of-restate && cd java-tour-of-restate ``` -------------------------------- ### Get Java Hello World (Maven/Spring) via CLI Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Java Hello World example using Maven and Spring Boot via the Restate CLI. ```shell restate example java-hello-world-maven-spring-boot && cd java-hello-world-maven-spring-boot ``` -------------------------------- ### Get Rust Greeter service template (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Rust Greeter service example using the Restate CLI and navigates into the project directory. ```shell restate example rust-hello-world && cd rust-hello-world ``` -------------------------------- ### Launch Restate SDK Example Programs Source: https://github.com/restatedev/documentation/blob/main/static/tsdocs/index.html Run example programs for greeter, object, and workflow services without requiring a full build. ```bash npm run -w packages/restate-sdk-examples greeter npm run -w packages/restate-sdk-examples object npm run -w packages/restate-sdk-examples workflow ``` -------------------------------- ### Download and Run Python Example (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Download the Python tour example using wget, unzip it, and navigate to the directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/python-tour-of-restate.zip && unzip python-tour-of-restate.zip -d python-tour-of-restate && rm python-tour-of-restate.zip ``` -------------------------------- ### Download and Run Python Example (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Use the Restate CLI to download and navigate to the Python tour example. ```shell restate example python-tour-of-restate && cd python-tour-of-restate ``` -------------------------------- ### Download and Run Rust Example (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Download the Rust tour example using wget, unzip it, and navigate to the directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/rust-tour-of-restate.zip && unzip rust-tour-of-restate.zip -d rust-tour-of-restate && rm rust-tour-of-restate.zip && cd rust-tour-of-restate ``` -------------------------------- ### Download and Run Rust Example (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Use the Restate CLI to download and navigate to the Rust tour example. ```shell restate example rust-tour-of-restate && cd rust-tour-of-restate ``` -------------------------------- ### Get Rust Shuttle Greeter service template (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Rust Shuttle Greeter service example as a zip archive, extracts it, and navigates into the project directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/rust-shuttle-hello-world.zip && unzip rust-shuttle-hello-world.zip -d rust-shuttle-hello-world && rm rust-shuttle-hello-world.zip && cd rust-shuttle-hello-world ``` -------------------------------- ### Run Restate Server with Homebrew Source: https://github.com/restatedev/documentation/blob/main/docs/develop/local_dev.mdx After installation with Homebrew, use this command to start the Restate Server. ```shell restate-server ``` -------------------------------- ### Download and Install Restate Binaries (Linux x64) Source: https://github.com/restatedev/documentation/blob/main/docs/develop/local_dev.mdx Installs Restate Server and CLI for Linux x64 by downloading binaries. Ensure the installation directory is in your PATH. ```shell BIN=$HOME/.local/bin && RESTATE_PLATFORM=x86_64-unknown-linux-musl && \ curl -L --remote-name-all https://restate.gateway.scarf.sh/latest/restate-{server,cli}-$RESTATE_PLATFORM.tar.xz && \ tar -xvf restate-server-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-server-$RESTATE_PLATFORM/restate-server && \ tar -xvf restate-cli-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-cli-$RESTATE_PLATFORM/restate && \ chmod +x restate restate-server && \ # Move the binaries to a directory in your PATH, for example ~/.local/bin: mv restate $BIN && \ mv restate-server $BIN ``` -------------------------------- ### Get Rust Shuttle Greeter service template (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Downloads the Rust Shuttle Greeter service example using the Restate CLI and navigates into the project directory. ```shell restate example rust-shuttle-hello-world && cd rust-shuttle-hello-world ``` -------------------------------- ### Download and Install Restate Binaries (Linux arm64) Source: https://github.com/restatedev/documentation/blob/main/docs/develop/local_dev.mdx Installs Restate Server and CLI for Linux arm64 by downloading binaries. Ensure the installation directory is in your PATH. ```shell BIN=$HOME/.local/bin && RESTATE_PLATFORM=aarch64-unknown-linux-musl && \ curl -L --remote-name-all https://restate.gateway.scarf.sh/latest/restate-{server,cli}-$RESTATE_PLATFORM.tar.xz && \ tar -xvf restate-server-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-server-$RESTATE_PLATFORM/restate-server && \ tar -xvf restate-cli-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-cli-$RESTATE_PLATFORM/restate && \ chmod +x restate restate-server && \ # Move the binaries to a directory in your PATH, for example ~/.local/bin: mv restate $BIN && \ mv restate-server $BIN ``` -------------------------------- ### Run Part 4 Example (Java) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Execute the Part 4 example for the ticket reservation system using Gradle. ```shell ./gradlew -PmainClass=dev.restate.tour.part4.AppMain run ``` -------------------------------- ### Run Part 4 Example (Go) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Execute the Part 4 example for the ticket reservation system using the Go command. ```shell go run ./part4 ``` -------------------------------- ### Download Java Maven Example via wget Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Download the Java Maven example using wget, unzip it, and navigate to the project directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-maven.zip && unzip java-hello-world-maven.zip -d java-hello-world-maven && rm java-hello-world-maven.zip && cd java-hello-world-maven ``` -------------------------------- ### Download and Run TypeScript Example (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Download the TypeScript tour example using wget, unzip it, and navigate to the directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/typescript-tour-of-restate.zip && unzip typescript-tour-of-restate.zip -d typescript-tour-of-restate && rm typescript-tour-of-restate.zip ``` -------------------------------- ### Download and Run TypeScript Example (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Use the Restate CLI to download and navigate to the TypeScript tour example. ```shell restate example typescript-tour-of-restate && cd typescript-tour-of-restate ``` -------------------------------- ### start Source: https://github.com/restatedev/documentation/blob/main/static/tsdocs/classes/_restatedev_restate-sdk-testcontainers.RestateContainer.html Starts the test container and returns a promise that resolves with the started container. ```APIDOC ## start ### Description Starts the test container and returns a promise that resolves with the started container. ### Method start() ### Returns Promise ### Example ```typescript // Assuming 'container' is an instance of RestateContainer const startedContainer = await container.start(); ``` ``` -------------------------------- ### Start Local Development Server Source: https://github.com/restatedev/documentation/blob/main/README.md Starts a local development server for the documentation. Changes are reflected live without requiring a server restart. ```bash yarn start ``` -------------------------------- ### Install Restate Server and CLI Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Installs the Restate server and CLI binaries. Ensure you have the correct platform tarball and move the binaries to a directory in your PATH. ```shell tar -xvf restate-server-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-server-$RESTATE_PLATFORM/restate-server && \ tar -xvf restate-cli-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-cli-$RESTATE_PLATFORM/restate && \ chmod +x restate restate-server && \ # Move the binaries to a directory in your PATH, for example /usr/local/bin (needs sudo): sudo mv restate $BIN && \ sudo mv restate-server $BIN ``` -------------------------------- ### Download Java Maven Example via CLI Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Download the Java Maven example using the Restate CLI and navigate to the project directory. ```shell restate example java-hello-world-maven && cd java-hello-world-maven ``` -------------------------------- ### Start Service Source: https://github.com/restatedev/documentation/blob/main/docs/guides/cron.mdx Start the service using the appropriate command for TypeScript, Java, or Go. ```shell npx tsx watch ./src/cron/task_service.ts ``` ```shell ./gradlew -PmainClass=my.example.cron.TaskService run ``` ```shell go run ./src/cron ``` -------------------------------- ### Setup Restate Test Environment Source: https://github.com/restatedev/documentation/blob/main/docs/develop/ts/testing.mdx Starts a Restate container and registers services using a user-provided closure. An optional second argument allows for custom Testcontainers. ```typescript import { RestateTestEnvironment } from "@restatedev/restate-sdk-testcontainers"; import { Counter } from "./counter"; const environment = await RestateTestEnvironment.start({ services: [Counter], }); // ... use environment ``` -------------------------------- ### start() Source: https://github.com/restatedev/documentation/blob/main/static/ktdocs/sdk-testing/dev.restate.sdk.testing/-restate-runner/start.html Runs the Restate instance, starts the embedded service endpoint server, and registers the provided services. ```APIDOC ## start() ### Description Runs the Restate instance, starts the embedded service endpoint server, and registers the provided services. ### Signature open fun start() ### Remarks This function is part of the RestateRunner class and is used to initiate a Restate environment for testing purposes. ``` -------------------------------- ### Download Java Gradle Example via wget Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Download the Java Gradle example using wget, unzip it, and navigate to the project directory. ```shell wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-gradle.zip && unzip java-hello-world-gradle.zip -d java-hello-world-gradle && rm java-hello-world-gradle.zip && cd java-hello-world-gradle ``` -------------------------------- ### Run Part 4 Example (Python) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Execute the Part 4 example for the ticket reservation system using Hypercorn. ```shell python3 -m hypercorn -b localhost:9080 tour/part4/app:app ``` -------------------------------- ### Download and Unzip Java Maven Quarkus Example Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Download the Java Maven Quarkus example, unzip it, and navigate to the project directory. ```shell unzip java-hello-world-maven-quarkus.zip -d java-hello-world-maven-quarkus && rm java-hello-world-maven-quarkus.zip && cd java-hello-world-maven-quarkus ``` -------------------------------- ### start Source: https://github.com/restatedev/documentation/blob/main/static/tsdocs/classes/_restatedev_restate-sdk-testcontainers.RestateTestEnvironment.html Starts the Restate test environment. It takes a function to mount services and an optional factory for the Restate container. ```APIDOC ## start ### Description Starts the Restate test environment, allowing you to mount services and configure the Restate container. ### Method Signature `start(mountServicesFn: (server: RestateEndpoint) => void, restateContainerFactory?: () => GenericContainer): Promise` ### Parameters * `mountServicesFn`: A function that takes a `RestateEndpoint` and mounts services to it. * `restateContainerFactory`: An optional function that returns a `GenericContainer` for the Restate instance. ### Returns A `Promise` that resolves to a `RestateTestEnvironment` instance. ``` -------------------------------- ### Install Restate via Homebrew Source: https://github.com/restatedev/documentation/blob/main/docs/develop/local_dev.mdx Use this command to install the Restate Server and CLI using Homebrew. ```shell brew install restatedev/tap/restate-server restatedev/tap/restate ``` -------------------------------- ### Download Java Gradle Example via CLI Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Download the Java Gradle example using the Restate CLI and navigate to the project directory. ```shell restate example java-hello-world-gradle && cd java-hello-world-gradle ``` -------------------------------- ### Install Restate via npm Source: https://github.com/restatedev/documentation/blob/main/docs/develop/local_dev.mdx Use this command to install the Restate Server and CLI globally using npm. ```shell npm install --global @restatedev/restate-server@latest @restatedev/restate@latest ``` -------------------------------- ### Get Cloudflare Worker Example Source: https://github.com/restatedev/documentation/blob/main/docs/deploy/services/faas/workers.md Use the Restate CLI to fetch the Cloudflare Worker TypeScript template for a quick start. ```shell restate example typescript-cloudflare-worker-hello-world && cd typescript-cloudflare-worker-hello-world ``` -------------------------------- ### Go Virtual Object Example Source: https://github.com/restatedev/documentation/blob/main/docs/concepts/services.mdx Example of a virtual object implementation in Go. Use this for defining stateful services. ```go CODE_LOAD::go/concepts/virtualobjects/main.go?4 ``` -------------------------------- ### Run Part 4 Example (Rust) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Execute the Part 4 example for the ticket reservation system using Cargo. ```shell cargo run --bin part4 ``` -------------------------------- ### Run Part 4 Example (TypeScript) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Execute the Part 4 example for the ticket reservation system using npm. ```shell npm run part4 ``` -------------------------------- ### Start Kafka Cluster Source: https://github.com/restatedev/documentation/blob/main/docs/guides/kafka-quickstart.mdx Execute this command in your terminal after creating the docker-compose.yaml file to start the Kafka cluster. Ensure Docker Compose is installed and configured. ```shell docker compose up ``` -------------------------------- ### Install Restate CLI and Server (Linux/WSL) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Installs the Restate CLI and server binaries on Linux or WSL. Ensure your PATH includes the directory where binaries are moved. ```shell BIN=~/.local/bin && RESTATE_PLATFORM=x86_64-unknown-linux-gnu && \ curl -L --remote-name-all https://restate.gateway.scarf.sh/latest/restate-{server,cli}-$RESTATE_PLATFORM.tar.xz && \ tar -xvf restate-server-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-server-$RESTATE_PLATFORM/restate-server && \ tar -xvf restate-cli-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-cli-$RESTATE_PLATFORM/restate && \ chmod +x restate restate-server && \ # Move the binaries to a directory in your PATH, for example ~/.local/bin: mv restate $BIN && \ mv restate-server $BIN ``` -------------------------------- ### Download and Install Restate Binaries (MacOS arm64) Source: https://github.com/restatedev/documentation/blob/main/docs/develop/local_dev.mdx Installs Restate Server and CLI for MacOS arm64 by downloading binaries. Requires sudo to move binaries to /usr/local/bin. ```shell BIN=/usr/local/bin && RESTATE_PLATFORM=aarch64-apple-darwin && \ curl -L --remote-name-all https://restate.gateway.scarf.sh/latest/restate-{server,cli}-$RESTATE_PLATFORM.tar.xz && \ tar -xvf restate-server-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-server-$RESTATE_PLATFORM/restate-server && \ tar -xvf restate-cli-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-cli-$RESTATE_PLATFORM/restate && \ chmod +x restate restate-server && \ # Move the binaries to a directory in your PATH, for example /usr/local/bin (needs sudo): sudo mv restate $BIN && \ sudo mv restate-server $BIN ``` -------------------------------- ### Select Example with Awakeables Source: https://github.com/restatedev/documentation/blob/main/static/javadocs/dev/restate/sdk/Select.html Demonstrates how to use the Select class to await multiple DurableFutures, including mapping success results and handling failures. This example uses awakeables for demonstration purposes. ```java var a1 = ctx.awakeable(String.class); var a2 = ctx.awakeable(MyObject.class); var a3 = ctx.awakeable(String.class); var result = Select.select() // Just select the a1 as is .or(a1) // When selecting a2, map the success result .when(a2, myObject -> myObject.toString()) // When selecting a3, map failure as another failure .when(a3, ThrowingFunction.identity(), ex -> { throw new TerminalException("a3 failed, too bad!"); }) // Finally await for the result .await(); ``` -------------------------------- ### Download and Install Restate Binaries (MacOS x64) Source: https://github.com/restatedev/documentation/blob/main/docs/develop/local_dev.mdx Installs Restate Server and CLI for MacOS x64 by downloading binaries. Requires sudo to move binaries to /usr/local/bin. ```shell BIN=/usr/local/bin && RESTATE_PLATFORM=x86_64-apple-darwin && \ curl -L --remote-name-all https://restate.gateway.scarf.sh/latest/restate-{server,cli}-$RESTATE_PLATFORM.tar.xz && \ tar -xvf restate-server-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-server-$RESTATE_PLATFORM/restate-server && \ tar -xvf restate-cli-$RESTATE_PLATFORM.tar.xz --strip-components=1 restate-cli-$RESTATE_PLATFORM/restate && \ chmod +x restate restate-server && \ # Move the binaries to a directory in your PATH, for example /usr/local/bin (needs sudo): sudo mv restate $BIN && \ sudo mv restate-server $BIN ``` -------------------------------- ### Add Code Snippet with Start and End Tags Source: https://github.com/restatedev/documentation/blob/main/README.md Example of how to define a specific section of a TypeScript code snippet using start and end tags for inclusion in documentation. ```typescript greet: async (ctx: restate.Context, name: string) => { // // option 1: use full API spec ctx.send(myGreeterApi).greet("Pete"); // } ``` -------------------------------- ### invocationHandle Source: https://github.com/restatedev/documentation/blob/main/static/ktdocs/sdk-api-kotlin/dev.restate.sdk.kotlin/invocation-handle.html Get an InvocationHandle for an already existing invocation. This will let you interact with a running invocation, for example to cancel it or retrieve its result. ```APIDOC ## invocationHandle ### Description Get an [InvocationHandle] for an already existing invocation. This will let you interact with a running invocation, for example to cancel it or retrieve its result. ### Parameters #### Path Parameters * **invocationId** (String) - Required - The invocation to interact with. * **responseClazz** (KClass) - Required - The response class. ``` -------------------------------- ### Example: Edit K/V State with CLI Source: https://github.com/restatedev/documentation/blob/main/docs/operate/introspection.mdx An example demonstrating how to edit the K/V state for a specific service and key using the Restate CLI. It shows the interactive confirmation prompt. ```shell restate kv edit counter bob ``` -------------------------------- ### Cloudflare Workers Service Output Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Example output when running the Cloudflare Workers Restate service, indicating the local server has started. ```log restate-cloudflare-worker-template@0.0.1 dev > wrangler dev --port 9080 ⛅️ wrangler 3.88.0 ------------------- ╭────────────────────────────────────────────────────────────────────────────────────────⎔ Starting local server... [wrangler:inf] Ready on http://localhost:9080 ``` -------------------------------- ### Install restatectl for Linux x64 via Binary Download Source: https://github.com/restatedev/documentation/blob/main/docs/operate/clusters.mdx Download and install the restatectl binary for Linux x64. Ensure the binary is moved to a directory in your PATH. ```shell BIN=$HOME/.local/bin && RESTATE_PLATFORM=x86_64-unknown-linux-musl && \ curl -LO https://restate.gateway.scarf.sh/latest/restatectl-$RESTATE_PLATFORM.tar.xz && \ tar -xvf restatectl-$RESTATE_PLATFORM.tar.xz --strip-components=1 restatectl-$RESTATE_PLATFORM/restatectl && \ chmod +x restatectl && \ # Move the binary to a directory in your PATH, for example ~/.local/bin: mv restatectl $BIN ``` -------------------------------- ### Deno Service Output Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Example output when running the Deno Restate service, showing the watcher process has started and is listening on port 9080. ```log Task dev deno run --allow-net --allow-env --watch main.ts Watcher Process started. Listening on http://0.0.0.0:9080/ ``` -------------------------------- ### Database Interaction Example Source: https://github.com/restatedev/documentation/blob/main/docs/guides/databases.mdx Demonstrates various patterns for accessing databases from Restate handlers. Ensure you have the necessary database client libraries installed. ```typescript import * as restate from "@restatedev/restate-sdk"; const app = restate.createApp(new restate.LocalServices()); // Example: Fetching data from a database app.handle(restate.object({ name: "myObject" }), { async greet(ctx: restate.ObjectContext, name: string): Promise { // Replace with your actual database query logic const userData = await ctx.sideEffect(async () => { // Simulate database call console.log("Simulating database call..."); await new Promise(resolve => setTimeout(resolve, 100)); // Simulate latency return { id: 1, name: "John Doe", email: "john.doe@example.com" }; }); return `Hello, ${userData.name}! Your email is ${userData.email}.`; }, }); // Example: Storing data in a database app.handle(restate.object({ name: "myObject" }), { async updateUser(ctx: restate.ObjectContext, id: number, email: string): Promise { await ctx.sideEffect(async () => { // Simulate database update console.log(`Simulating database update for user ID: ${id}...`); await new Promise(resolve => setTimeout(resolve, 100)); // Simulate latency console.log("User updated successfully."); }); }, }); // Example: Performing a transaction that involves a database update app.handle(restate.object({ name: "myObject" }), { async processOrder(ctx: restate.ObjectContext, orderId: string, userId: number): Promise { await ctx.runInBestEffortScope(async () => { // Simulate database operations within a transaction await ctx.sideEffect(async () => { console.log(`Updating order ${orderId} status in database...`); await new Promise(resolve => setTimeout(resolve, 50)); console.log("Order status updated."); }); await ctx.sideEffect(async () => { console.log(`Updating user ${userId} order history in database...`); await new Promise(resolve => setTimeout(resolve, 50)); console.log("User order history updated."); }); }); }, }); // To run this example, you would typically start the Restate server and then invoke these handlers. // For local testing, you can use the Restate CLI: // restate run --node-main src/database/main.ts ``` -------------------------------- ### RestateTest Annotation Example Source: https://github.com/restatedev/documentation/blob/main/static/javadocs/dev/restate/sdk/testing/RestateTest.html Annotate your test class with @RestateTest to start a Restate environment. Bind your services using @BindService and inject clients with @RestateClient. ```java @RestateTest class CounterTest { @BindService private final Counter counter = new Counter(); @Test void testGreet(@RestateClient Client ingressClient) { var client = CounterClient.fromClient(ingressClient, "my-counter"); long response = client.get(); assertThat(response).isEqualTo(0L); } } ``` -------------------------------- ### Get Cron Job Info Source: https://github.com/restatedev/documentation/blob/main/docs/guides/cron.mdx Retrieve information about a specific cron job using its job ID. This example is shown for TypeScript, Java, and Go. ```shell curl localhost:8080/CronJob/myJobId/getInfo ``` ```shell curl localhost:8080/CronJob/myJobId/getInfo ``` ```shell curl localhost:8080/CronJob/myJobId/GetInfo ``` -------------------------------- ### Transactional Event Processing with Restate Source: https://github.com/restatedev/documentation/blob/main/docs/use-cases/event-processing.mdx Implement transactional event processing using Restate. This example demonstrates the core setup for handling events transactionally. ```TypeScript CODE_LOAD::ts/src/use_cases/event_processing/transactional_event_processing.ts?2 ``` -------------------------------- ### Python Service Implementation Source: https://github.com/restatedev/documentation/blob/main/docs/concepts/services.mdx Illustrates a simple service in Python for durable execution. This example demonstrates the basic setup for a Restate service using Python. ```python from typing import Any from restate.aio import ``` -------------------------------- ### Define a Restate Virtual Object Source: https://github.com/restatedev/documentation/blob/main/static/tsdocs/functions/_restatedev_restate-sdk.object.html Example of defining a virtual object named 'counter' with 'add' and 'get' handlers. This is the basic structure for creating a virtual object. ```typescript const counter = object({ name: "counter", handlers: { add: async (ctx: ObjectContext, amount: number) => {}, get: async (ctx: ObjectContext) => {} } }) ``` -------------------------------- ### Describe a Deployment via CLI Source: https://github.com/restatedev/documentation/blob/main/docs/operate/versioning.mdx To get detailed information about a specific deployment, use the `restate deployment describe` command followed by the deployment ID. Deployment IDs start with `dp_`. ```bash restate deployment describe dp_14LsPzGz9HBxXIeBoH5wYUh ``` -------------------------------- ### Reference GitHub Raw Code Snippet with Tags Source: https://github.com/restatedev/documentation/blob/main/README.md Example of referencing a specific section of a TypeScript code snippet directly from a GitHub raw URL using start and end tags. ```markdown CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/main/tutorials/tour-of-restate-typescript/src/part1/user_session.ts#- ``` -------------------------------- ### Deploy Restate Cluster with Docker Compose Source: https://github.com/restatedev/documentation/blob/main/docs/guides/cluster.mdx This YAML configuration defines a 3-node Restate cluster, including a Minio instance for S3-compatible storage. Ensure Docker and Docker Compose are installed. Run `docker compose up` in the directory containing this file to start the cluster. ```yaml x-environment: &common-env RESTATE_CLUSTER_NAME: "restate-cluster" # For more on logging, see: https://docs.restate.dev/operate/monitoring/logging RESTATE_LOG_FILTER: "restate=info" RESTATE_DEFAULT_REPLICATION: 2 # We require minimum of 2 nodes to accept writes # The addresses where nodes can reach each other over the "internal" Docker Compose network RESTATE_METADATA_CLIENT__ADDRESSES: '["http://restate-1:5122","http://restate-2:5122","http://restate-3:5122"]' # Partition snapshotting, see: https://docs.restate.dev/operate/snapshots RESTATE_WORKER__SNAPSHOTS__DESTINATION: "s3://restate/snapshots" RESTATE_WORKER__SNAPSHOTS__SNAPSHOT_INTERVAL_NUM_RECORDS: "1000" RESTATE_WORKER__SNAPSHOTS__AWS_REGION: "local" RESTATE_WORKER__SNAPSHOTS__AWS_ENDPOINT_URL: "http://minio:9000" RESTATE_WORKER__SNAPSHOTS__AWS_ALLOW_HTTP: true RESTATE_WORKER__SNAPSHOTS__AWS_ACCESS_KEY_ID: "minioadmin" RESTATE_WORKER__SNAPSHOTS__AWS_SECRET_ACCESS_KEY: "minioadmin" x-defaults: &defaults image: docker.restate.dev/restatedev/restate:VAR::RESTATE_VERSION extra_hosts: - "host.docker.internal:host-gateway" volumes: - restate-data:/restate-data services: restate-1: <<: *defaults ports: - "8080:8080" # Ingress - "9070:9070" # Admin - "5122:5122" # Node-to-node communication environment: <<: *common-env RESTATE_NODE_NAME: restate-1 RESTATE_FORCE_NODE_ID: 1 RESTATE_ADVERTISED_ADDRESS: "http://restate-1:5122" # Other Restate nodes must be able to reach us using this address RESTATE_AUTO_PROVISION: "true" # Only the first node provisions the cluster restate-2: <<: *defaults ports: - "25122:5122" - "29070:9070" - "28080:8080" environment: <<: *common-env RESTATE_NODE_NAME: restate-2 RESTATE_FORCE_NODE_ID: 2 RESTATE_ADVERTISED_ADDRESS: "http://restate-2:5122" RESTATE_AUTO_PROVISION: "false" restate-3: <<: *defaults ports: - "35122:5122" - "39070:9070" - "38080:8080" environment: <<: *common-env RESTATE_NODE_NAME: restate-3 RESTATE_FORCE_NODE_ID: 3 RESTATE_ADVERTISED_ADDRESS: "http://restate-3:5122" RESTATE_AUTO_PROVISION: "false" minio: image: quay.io/minio/minio entrypoint: "/bin/sh" # Ensure a bucket called "restate" exists on startup: command: "-c 'mkdir -p /data/restate && /usr/bin/minio server --quiet /data'" ports: - "9000:9000" ``` -------------------------------- ### Create and Set Up TypeScript Hello World Project (CLI) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Use the Restate CLI to generate a TypeScript hello world project and install its dependencies. ```shell restate example typescript-hello-world && cd typescript-hello-world && npm install ``` -------------------------------- ### Signup Workflow Implementation (Go) Source: https://github.com/restatedev/documentation/blob/main/docs/use-cases/workflows.mdx Example of implementing a signup workflow using Restate's durable building blocks in Go. This snippet demonstrates the core logic for a workflow. ```Go package workflows import ( "context" "fmt" "github.com/restatedev/restate-sdk-go/restate" ) func SignupWorkflow(ctx restate.WorkflowContext, name string) error { user, err := ctx.Run(ctx, "get-user", func(ctx context.Context) (any, error) { return getUser(name) }) if err != nil { return err } if user == nil { if err := ctx.Run(ctx, "send-welcome-email", func(ctx context.Context) (any, error) { return nil, sendWelcomeEmail(name) }); err != nil { return err } if err := ctx.Run(ctx, "send-signup-notification", func(ctx context.Context) (any, error) { return nil, sendSignupNotification(name) }); err != nil { return err } } return nil } func getUser(name string) (*User, error) { // In a real application, this would be an RPC call to a user service. // For demonstration purposes, we simulate a user lookup. if name == "Alice" { return &User{Name: "Alice"}, } return nil, } func sendWelcomeEmail(name string) error { fmt.Printf("Sending welcome email to %s...\n", name) // Simulate sending an email return nil } func sendSignupNotification(name string) error { fmt.Printf("Sending signup notification for %s...\n", name) // Simulate sending a notification return nil } // Dummy User struct for demonstration type User struct { Name string } ``` -------------------------------- ### Get Number Source: https://github.com/restatedev/documentation/blob/main/static/javadocs/dev/restate/sdk/core/generated/protocol/Protocol.GetInvocationOutputCommandMessage.TargetCase.html Gets the numerical representation of the enum constant. ```APIDOC ## getNumber() ### Description Returns the numerical representation of this enum constant. ### Specified by `getNumber` in interface `com.google.protobuf.Internal.EnumLite` ### Returns The integer value of the enum constant. ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Create and activate a Python virtual environment for the project. ```shell python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### start Source: https://github.com/restatedev/documentation/blob/main/static/javadocs/dev/restate/sdk/springboot/RestateHttpEndpointBean.html Starts the lifecycle of the bean. This method is specified by the Lifecycle interface. ```APIDOC ## start ### Description Starts the lifecycle of the bean. This method is specified by the Lifecycle interface. ### Method public void start() ### Specified by: `start` in interface `org.springframework.context.Lifecycle` ``` -------------------------------- ### Install Python Requirements Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Install the necessary Python packages for the project. ```shell pip install -r requirements.txt ``` -------------------------------- ### start Source: https://github.com/restatedev/documentation/blob/main/static/javadocs/dev/restate/sdk/springboot/RestateHttpEndpointBean.html Starts the lifecycle component. This method is part of the Lifecycle and SmartLifecycle interfaces. ```APIDOC ## start() ### Description Starts the lifecycle component. This method is part of the `Lifecycle` and `SmartLifecycle` interfaces. ### Method `void start()` ``` -------------------------------- ### Install and Build TypeScript Project Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Install project dependencies and build the TypeScript application. ```shell npm install && npm run build ``` -------------------------------- ### Run Go Services Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Start the Go services. ```shell go run ./app ``` -------------------------------- ### Run the Greeter Service Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Starts the Go Greeter service, which will listen for requests on port 9080. ```shell go run . ``` -------------------------------- ### Start Service Source: https://github.com/restatedev/documentation/blob/main/docs/guides/sagas.mdx Run the Sagas service for your specific SDK. This command starts the workflow execution. ```shell npx tsx watch ./src/sagas/booking_workflow.ts ``` ```shell ./gradlew -PmainClass=my.example.sagas.BookingWorkflow run ``` ```shell ./gradlew -PmainClass=my.example.sagas.BookingWorkflowKt run ``` ```shell python sagas/app.py ``` ```shell go run ./src/sagas ``` -------------------------------- ### Install restatectl with npm Source: https://github.com/restatedev/documentation/blob/main/docs/operate/clusters.mdx Use this command to install the restatectl CLI globally using npm. ```shell npm install --global @restatedev/restatectl@latest ``` ```shell restatectl ``` -------------------------------- ### Create and Set Up TypeScript Next.js Hello World Project Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Generate a TypeScript Next.js hello world project and install its dependencies. ```shell restate example typescript-nextjs-hello-world && cd typescript-nextjs-hello-world && npm install ``` -------------------------------- ### Start Restate Server with Configuration Source: https://github.com/restatedev/documentation/blob/main/docs/guides/kafka-quickstart.mdx Launch the Restate server using the provided configuration file. This command assumes the 'restate.toml' file is in the current directory. ```shell restate-server --config-file restate.toml ``` -------------------------------- ### Create and Set Up TypeScript Bun Hello World Project Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Generate a TypeScript Bun hello world project and install its dependencies. ```shell restate example typescript-bun-hello-world && cd typescript-bun-hello-world && npm install ``` -------------------------------- ### Get Greeter Service Template (wget) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/quickstart.mdx Fetches the Go Greeter service template by downloading and unzipping a release archive. ```shell wget https://github.com/restatedev/examples/releases/latest/download/go-hello-world.zip && unzip go-hello-world.zip -d go-hello-world && rm go-hello-world.zip && cd go-hello-world ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/restatedev/documentation/blob/main/README.md Installs project dependencies using Yarn. This is the first step before running any development commands. ```bash yarn ``` -------------------------------- ### Run Part 1 of the Tour (Java) Source: https://github.com/restatedev/documentation/blob/main/docs/get_started/tour.mdx Execute the first part of the Restate tour using Gradle. ```shell ./gradlew -PmainClass=dev.restate.tour.part1.AppMain run ``` -------------------------------- ### Rust Virtual Object Example Source: https://github.com/restatedev/documentation/blob/main/docs/concepts/services.mdx Example of a virtual object implementation in Rust. Use this for defining stateful services. ```rust CODE_LOAD::rust/src/concepts/vo.rs?4 ```