Getting access to the Request
in a FromForm
instance OR requiring a guard in an uri!
macro
#2408
Unanswered
42triangles
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am curious how to best handle what conceptually feels in between a request guard and a form, where the form data has to be validated against the database (⇒
FromRequest
), while it still should be necessary foruri!
macros (⇒FromForm
).With a
POST
request that wouldn't be an issue because based on what I've seen,FromData
does have access to theRequest
.However, for
GET
requests the same doesn't work, since doing the?<form..>
thing requiresFromForm
which does not allow using theRequest
to get in this case access to the database connection.And while a request guard could handle the validation (even though
Request::query_value
does note that it is much more expensive than the normal way of retrieving them, and is to be avoided if possible), it is not something that then becomes necessary in theuri!
macro which I would like to use for safe URI generation.A possible way of getting close that I've considered would be using a
FromForm
instance that doesn't do anything with the data it is given, and a request guard that does the validation; though the effective double lookup does feel rather... unidiomatic.Another way would just be to do validation in the body of the function, which is probably the best course of action unless I have overlooked anything.
Beta Was this translation helpful? Give feedback.
All reactions