Prim+RPC by default will serialize messages passed to it using the default JSON “stringify” method to serialize RPC and the destr library to deserialize RPC. This JSON handler implementation can be swapped out with any other library to support advanced types like Dates, Maps, Sets, or others.
We can provide our own JSON handler that resembles the default JSON handler (with a few optional additions). See the configuration page for the JSON Handler for more details on setting up your own or browse popular examples on this page.
In all cases, the JSON handler must be the same on both the client and server. This list is non-exhaustive and you may choose to implement your own JSON handler.
SuperJSON allows additional types to be used with Prim+RPC. The JSON handler will look like this:
MsgPack supports additional types including ArrayBuffer types. While it is not JSON, it can be used with Prim+RPC. There are also several implementations of MsgPack and you may choose one that best suits your needs.
We’ll add a few additional options to the handler to allow Prim+RPC plugins to better work with binary data:
Like the SuperJSON example, devalue may be used to support additional types with Prim+RPC. The JSON handler can be set up like so:
YAML may be used with Prim+RPC and may be a more readable alternative to JSON. The JSON-like handler can be set up like so:
These are some popular examples but Prim+RPC can be configured to use other JSON or JSON-like handlers.Report an Issue