-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/main' into python_tour
# Conflicts: # code_snippets/go/go.mod # code_snippets/go/go.sum # docs/get_started/tour.mdx # restate.config.json
- Loading branch information
Showing
19 changed files
with
1,257 additions
and
1,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as restate from "@restatedev/restate-sdk"; | ||
import {Context, WorkflowContext} from "@restatedev/restate-sdk"; | ||
|
||
// <start_service_definition> | ||
const myService = restate.service({ | ||
name: "MyService", | ||
handlers: { | ||
myHandler: restate.handlers.handler({ | ||
// Set the input serde here | ||
input: restate.serde.binary, | ||
// Set the output serde here | ||
output: restate.serde.binary | ||
}, async (ctx: Context, data: Uint8Array): Promise<Uint8Array> => { | ||
// Process the request | ||
return data; | ||
}), | ||
}, | ||
}); | ||
// <end_service_definition> | ||
|
||
let ctx: WorkflowContext = undefined as unknown as WorkflowContext; | ||
let input = new Uint8Array(); | ||
|
||
// <start_client> | ||
ctx.serviceClient(myService) | ||
.myHandler( | ||
input, | ||
restate.rpc.opts({ | ||
input: restate.serde.binary, | ||
output: restate.serde.binary | ||
}) | ||
); | ||
// <end_client> | ||
|
||
// <start_state> | ||
ctx.get("my-binary-data", restate.serde.binary); | ||
ctx.set("my-binary-data", new Uint8Array(), restate.serde.binary); | ||
// <end_state> | ||
|
||
// <start_awakeable> | ||
ctx.awakeable(restate.serde.binary) | ||
// <end_awakeable> | ||
|
||
// <start_run> | ||
ctx.run("my-side-effect", () => new Uint8Array(), { serde: restate.serde.binary }); | ||
// <end_run> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
sidebar_position: 9 | ||
description: "How to serialize and deserialize data with the Restate SDK." | ||
--- | ||
|
||
# Serialization | ||
|
||
Restate sends data over the network for storing state, journaling actions, awakeables, etc. | ||
|
||
By default, Typescript SDK uses the built-in [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) | ||
support to perform (de)serialization, but it is possible to override this behavior using the `Serde` interface. | ||
|
||
For example, to customize the `Serde` to use for the handler input and output: | ||
|
||
```typescript | ||
CODE_LOAD::ts/src/develop/serialization.ts#service_definition | ||
``` | ||
|
||
To customize the serde to use on requests: | ||
|
||
```typescript | ||
CODE_LOAD::ts/src/develop/serialization.ts#client | ||
``` | ||
|
||
When sending a request to a handler configured with custom serde(s) you always need to manually specify them, because the client does not automatically infer what serde(s) should be used. | ||
|
||
To customize the serde to use for state: | ||
|
||
```typescript | ||
CODE_LOAD::ts/src/develop/serialization.ts#state | ||
``` | ||
|
||
For awakeables: | ||
|
||
```typescript | ||
CODE_LOAD::ts/src/develop/serialization.ts#awakeable | ||
``` | ||
|
||
For `run`: | ||
|
||
```typescript | ||
CODE_LOAD::ts/src/develop/serialization.ts#run | ||
``` |
Oops, something went wrong.