|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 - Restate Software, Inc., Restate GmbH |
| 3 | + * |
| 4 | + * This file is part of the Restate SDK for Node.js/TypeScript, |
| 5 | + * which is released under the MIT license. |
| 6 | + * |
| 7 | + * You can find a copy of the license in file LICENSE in the root |
| 8 | + * directory of this repository or package, or at |
| 9 | + * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE |
| 10 | + */ |
| 11 | + |
| 12 | +/* eslint-disable no-console */ |
| 13 | + |
| 14 | +import express, { Request, Response } from "express"; |
| 15 | +import * as restate from "../src/public_api"; |
| 16 | + |
| 17 | +const rs = restate.connection({ ingress: "http://127.0.0.1:9090" }); |
| 18 | + |
| 19 | +const app = express(); |
| 20 | +app.use(express.json()); |
| 21 | + |
| 22 | +app.post("/workflow", async (req: Request, res: Response) => { |
| 23 | + const { id, name } = req.body; |
| 24 | + |
| 25 | + const response = await rs.invoke({ |
| 26 | + id, |
| 27 | + input: name, |
| 28 | + handler: async (ctx, name) => { |
| 29 | + const p1 = await ctx.sideEffect(async () => `Hello ${name}!`); |
| 30 | + const p2 = await ctx.sideEffect(async () => `Bonjour ${name}`); |
| 31 | + const p3 = await ctx.sideEffect(async () => `Hi ${name}`); |
| 32 | + // const p4 = await ctx |
| 33 | + // .rpc<{ greet: (name: string) => Promise<string> }>({ path: "greeter" }) |
| 34 | + // .greet(name); |
| 35 | + |
| 36 | + return p1 + p2 + p3; //+ p4; |
| 37 | + }, |
| 38 | + }); |
| 39 | + |
| 40 | + res.send(response); |
| 41 | +}); |
| 42 | + |
| 43 | +app.listen(3000); |
0 commit comments