Replies: 2 comments
-
It'd be interesting to see this pattern with decorators: @Requires("body", /* more attributes! */)
export default class Article extends Resource {
// happy resource lives here
} Or something more declarative, like: @Validate(Attribute("body").IsRequired, /* ... */)
export default class Article extends Resource {
// happy resource lives here
} |
Beta Was this translation helpful? Give feedback.
-
I think this approach it would be really cool too!. Especially the second one, 'cause it has more possibilities for custom validators :-) For example, I can imagine a User resource, with a SSN/DNI format validator, a lot of attributes existence validator, a password complexity validator, an email format validator, and a nickname/email not-used-already validator. |
Beta Was this translation helpful? Give feedback.
-
It would be cool, if we could add some kind of validation for resources, so that APIs can just define fields that should be validated at the moment that a resource is created/updated.
I believe that we could add this feature, by adding a new static property in the Resource definition, something like this:
The validation could be done asynchronously, to allow for validations dependant of other resources, and It would have the entire object to check, to allow for multi-field validations.
The function could be run at the ADD/UPDATE operations, and intercept those operations if the validation function throws an error. That error could be passed to the user making the request.
Beta Was this translation helpful? Give feedback.
All reactions