Validation functionality (discussion, input wanted)
See original GitHub issueI’m considering including some functionality for validating user input. Typical things that need to be validated are:
ctx.pathParam("user-id")
ctx.queryParam("isbn")
ctx.formParam("username")
You could potentially include the validate function on the Context
:
val isbn = ctx.validate(Param.QUERY, "isbn").matches(isbnRegex).get() ?: throw BadRequestResponse()
val username = ctx.validate(Param.FORM, "username").minLength(5).get() ?: throw BadRequestResponse()
But since there are a lot of possible entry points, a general validation function (util) would probably be better?
val isbn = validate(ctx.queryParam("isbn")).matches(isbnRegex).get() ?: throw BadRequestResponse()
val username = validate(ctx.formParam("username")).minLength(5).get() ?: throw BadRequestResponse()
This issue is intended for discussion. Should the functionality be included? If yes, how should it work?
Issue Analytics
- State:
- Created 5 years ago
- Comments:37 (30 by maintainers)
Top Results From Across the Web
Client-side form validation - Learn web development | MDN
Specifying the email type, for example, validates the inputs value against a well-formed email address pattern or a pattern matching a comma- ...
Read more >Designing Better Inline Validation UX - Smashing Magazine
Every input fields needs a conversation. For some fields, Ableton validates on blur, and for others validates only on submit.
Read more >When and how to choose HTML for form validation
Client-side form validation such as HTML5 gives users near-immediate feedback about whether or not their input data is valid.
Read more >What is Data Validation? How It Works and Why It's Important
Data validation is an essential part of any data handling task whether you're in the field collecting information, analyzing data, or preparing to...
Read more >User Input Validation | Controls - Pearson IT Certification
The validation controls are usually associated with input server controls on which the validation needs to be performed. For validation to work properly,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Out now as part of
2.2.0
!I like @bchristenson’s suggestion for putting the validator on the
Context
, with prefix/suffix for param type. Mainly because I’m really excited about the idea of auto-generating nice error messages.In my last suggestion I removed
getOrThrow
in favor of justget
, because I needed the cast to be part of theget
, likegetAs<Int>()
(getAsOrThrow<Int>(Exception.class)
doesn’t work). If we used your approach withasDouble()
(etc), we could go back to havinggetOrThrow()
: