New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous method validations #292

Closed
fayimora opened this Issue Jan 12, 2016 · 3 comments

Comments

2 participants
@fayimora
Contributor

fayimora commented Jan 12, 2016

Currently, @MethodValidation requires the method to return ValidationResult. Would it be possible to also support returning Future[ValidationResult]? Recently, I've had situations where my validation check returns a Future so I have to do something like:

myFut.map(truth => Validation.validate(truth, "Oops!"))

but that returns a Future[ValidationResult]

@cacoco

This comment has been minimized.

Member

cacoco commented Jan 14, 2016

The original intent of @MethodValidation is not for performing remote calls to do validation but more to provide validation on the parsed JSON request body.

Generally, the thinking is if you need to do a validation that requires an asynchronous call it would not be through this part of the framework. It is an interesting idea however to have something akin to this but I'm not sure it would be the current @MethodValidation.

Thanks,
-c

@cacoco cacoco closed this Jan 14, 2016

@fayimora

This comment has been minimized.

Contributor

fayimora commented Jan 15, 2016

@cacoco ok thanks 👍

I currently use @MethodValidation to validate data too. For instance, if I make a POST request to /api/users and I need to tell the client the username has been taken, I do the check in @MethodValidation. Does that mean I shouldn't be doing that?

@cacoco

This comment has been minimized.

Member

cacoco commented Jan 15, 2016

@fayimora it doesn't mean you can't or shouldn't do it that way. It just means we didn't design the current implementation of @MethodValidation for that use case. It's meant to be basic validation on the structure and values of the data coming in. We typically perform the remote calls as a second pass in validation after this layer.

Like I mentioned, it's an interesting idea but we probably wouldn't tie it to @MethodValidation in it's current form because@MethodValidation is highly integrated to JSON parsing right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment