I want to publish my rest api.How can I validate requests by their json schema to prevent storing unwanted data in the storage?
How can I validate requests by their json schema to prevent storing unwanted data in the storage?
@nkadd There’s a couple of ways to do create this logic. The first is to write your storage engine impl as logic in an RPC function. This way you can do whatever input validation you like and after write whatever logic you want.
The alternative approach would be to attach a before hook to the storage engine write operation. This lets your logic execute within the request pipeline before the write operation is handled by the internal logic in the server. You could validate the input JSON for the specific collection and key that’s to be written into.
Either approach works. The second one is scoped closely to the storage write operations while the first option is better if there’s other logic you’d want to execute as well (like send an in-app notification, etc). Hope this helps.