Validation support #330
Closed
eandre
started this conversation in
Suggestions
Replies: 1 comment
-
For visibility, this has been implemented (a long time ago!) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We're looking at adding better support for validating incoming requests. While we intend on providing a fully-fledged validation library in the future (and we have early designs for that that are looking promising), we also want to make it easy to do request validation today.
To make that happen, we propose defining an interface:
interface { Validate() error }
that, if implemented by a request payload, will result in Encore automatically calling theValidate
method after decoding the request. If theValidate
method reports a non-nil error the request will be aborted and the client will receive a validation error.If the validation function returns an
*errs.Error
that error is reported unmodified to the caller. Other errors are converted to an*errs.Error
with codeInvalidArgument
, which results in a HTTP response with status code400 Bad Request
.This design means that it's easy to use your validation library of choice. In the future we're looking to provide an out-of-the-box validation library for an even better developer experience.
Let us know what you think!
Beta Was this translation helpful? Give feedback.
All reactions