Skip to content

Commit

Permalink
Add Deno and Bun examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Jun 24, 2024
1 parent 5293cde commit 8c1b284
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 2 deletions.
10 changes: 10 additions & 0 deletions templates/bun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Hello world - Bun example

Sample project configuration of a Restate service using the TypeScript SDK and
Bun.

Have a look at the [TypeScript Quickstart guide](https://docs.restate.dev/get_started/quickstart?sdk=ts) for more information about the SDK.

You can run locally with `npm run dev` and register to Restate with
`restate dep add http://localhost:9080 --use-http1.1`. `--use-http1.1` is
always needed with Bun, as it does not yet support HTTP2.
18 changes: 18 additions & 0 deletions templates/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "restate-bun-template",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "bun run --watch src/index.ts",
"start": "bun run src/index.ts",
"format": "prettier --write \"src/*.+(js|ts|json)\""
},
"dependencies": {
"@restatedev/restate-sdk": "^1.0.1"
},
"devDependencies": {
"@types/bun": "^1.1.5",
"prettier": "^3.3.2",
"typescript": "^5.4.5"
}
}
24 changes: 24 additions & 0 deletions templates/bun/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Context, endpoint, service } from "@restatedev/restate-sdk/fetch";

// Template of a Restate service and handler
//
// Have a look at the TS QuickStart: https://docs.restate.dev/get_started/quickstart?sdk=ts
//

const greeter = service({
name: "greeter",
handlers: {
greet: async (ctx: Context, greeting: string) => {
return `${greeting}!`;
},
},
});

const handler = endpoint().bind(greeter).handler();

const server = Bun.serve({
port: 9080,
...handler,
});

console.log(`Listening on ${server.url}`);
12 changes: 12 additions & 0 deletions templates/bun/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"noEmit": true,
"module": "nodenext",
"target": "esnext",
"lib": ["esnext"],
"strict": true,
"moduleResolution": "nodenext",
"skipLibCheck": true
},
"exclude": ["node_modules", "dist", "test"]
}
3 changes: 1 addition & 2 deletions templates/cloudflare-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
"prettier": "^3.3.2",
"typescript": "^5.4.5",
"wrangler": "^3.0.0"
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
}
1 change: 1 addition & 0 deletions templates/deno/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deno.lock
15 changes: 15 additions & 0 deletions templates/deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Hello world - Deno example

Sample project configuration of a Restate service using the TypeScript SDK and
Deno.

Have a look at the [TypeScript Quickstart guide](https://docs.restate.dev/get_started/quickstart?sdk=ts) for more information about the SDK.

You can run locally with `deno task dev` and register to Restate with
`restate dep add http://localhost:9080 --use-http1.1`. `--use-http1.1` is
currently needed with local Deno as we do not support Deno's HTTP2
implementation yet.

You can deploy to Deno Deploy with `deployctl deploy` and register to Restate
with
`restate dep add https://<your-project-subdomain>.deno.dev/`.
6 changes: 6 additions & 0 deletions templates/deno/deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tasks": {
"dev": "deno run --allow-net --allow-env --watch main.ts",
"start": "deno run --allow-net --allow-env main.ts"
}
}
19 changes: 19 additions & 0 deletions templates/deno/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Context, endpoint, service } from "npm:@restatedev/restate-sdk@^1.0.1/fetch";

// Template of a Restate service and handler
//
// Have a look at the TS QuickStart: https://docs.restate.dev/get_started/quickstart?sdk=ts
//

const greeter = service({
name: "greeter",
handlers: {
greet: async (ctx: Context, greeting: string) => {
return `${greeting}!`;
},
},
});

const handler = endpoint().bind(greeter).handler();

Deno.serve({ port: 9080 }, handler.fetch);

0 comments on commit 8c1b284

Please sign in to comment.