Skip to main content

Serialization

Restate sends data over the network for storing state, journaling actions, awakeables, etc.

By default, Typescript SDK uses the built-in 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:


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;
}),
},
});

To customize the serde to use on requests:


ctx.serviceClient(myService)
.myHandler(
input,
restate.rpc.opts({
input: restate.serde.binary,
output: restate.serde.binary
})
);

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:


ctx.get("my-binary-data", restate.serde.binary);
ctx.set("my-binary-data", new Uint8Array(), restate.serde.binary);

For awakeables:


ctx.awakeable(restate.serde.binary)

For run:


ctx.run("my-side-effect", () => new Uint8Array(), { serde: restate.serde.binary });