Methods
Methods describe request-response calls in a protocol.
External methods are callable by connected clients. Internal methods are callable between Durable Object instances through a namespace handle.
Define a shared method
import { Schema as S } from "effect"
export const SendMessage = {
payload: S.Struct({
content: S.String,
}),
success: S.Struct({
messageId: S.String,
timestamp: S.Date,
}),
failure: S.Never,
}Shared methods such as UpdateProfile or ReportUser can live under a common shared/methods directory and be
inserted into a client's external table or a namespace's internal table.
Implement a shared handler
If a method is shared, its handler can be shared too.
import { Effect } from "effect"
import { handler } from "liminal"
import { UpdateProfile } from "../shared/methods/UpdateProfile.ts"
export default handler(
UpdateProfile,
Effect.fn(function* ({ displayName, avatarUrl }) {
// shared logic here
return { updated: true }
}),
)If the handler only makes sense for one actor, Actor.handler("Method", ...) is usually simpler for external methods.
Internal handlers are supplied to WorkerdActorRuntime.make({ internal: ... }).