Skip to main content

Servicers

For each of your data types you need to implement it's methods. You do that by implementing server-side (backend) servicers based on the data types and methods you defined (e.g., using Zod or protobuf).

For Python, you'll be creating subclasses of the code generated Servicer class where you can implement each of the methods you defined. For TypeScript you can either create subclasses or you can create an object literal.

For example, for a data type called Account:

from bank.v1.bank_rbt import Account

class AccountServicer(Account.Servicer):
# ...

Each method gets passed:

  • context: a subclass of Context specific to the method kind (e.g., ReaderContext)
  • request: the type defined in your Zod schema or .proto

To read and write the state of your data type from within one of your methods:

  • Python: self.state
  • TypeScript w/ classes: this.state
  • TypeScript w/ object literals: state argument passed into your method
important

When creating a subclasses of Servicer, there is a 1-1 mapping between an instance of your subclass and an instance of your data type that was either implicitly or explicitly created.

When using object literals in TypeScript, a single servicer may handles many different instances of your data types differentiated by different state arguments.

For more details on how to implement your methods see: