Skip to content
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

Request change: passing the validated results to the route as parameters #22

Closed
OmarThinks opened this issue Jan 29, 2021 · 2 comments
Closed

Comments

@OmarThinks
Copy link
Contributor

OmarThinks commented Jan 29, 2021

Request change: passing the validated results to the route as parameters


I can make this change.
After the data have been validated by the decorator,
Now the developer has to validate them again inside the route.


What if I could pass them after they have clean and validated into the route.
They will be passed from the decorator to the route automatically.
And the user will not have to validate them again in the route.

So the code will look like this:

@app.route("/", methods=["POST"])
@validate(body=BodyModel, query=QueryModel)
def post(requested):
	#Requested is validated
	body = requested.body
	# This is body after validation
	query = requested.query
	# This is query after validation
	name = body["name"]
	nickname = body["nickname"]
	age = query["age"]

This is all what the developer will have to write.
Cleaner code.


If God willed, I can make this change.
I request your permission to make this change
Thank you!

@bauerji
Copy link
Owner

bauerji commented Jan 29, 2021

Hi Omar,

I do not quite know what you meant by After the data have been validated by the decorator,
Now the developer has to validate them again inside the route.

There are two ways of how to pass validated parameters into your route function.

  • when you use validate() decorator arguments then validated parameters are accessible via request variable

  • using validated function kwargs type hints gives you direct access to these validated parameters.

I thing the latter one is what you are looking for.

Jirka

@OmarThinks
Copy link
Contributor Author

OmarThinks commented Jan 30, 2021

Hi Jirka!
That was exactly what I have meant.
If God willed, When I update the README.md, I will make sure that this is very clear.
Because this is what exactly what I came here to this package looking for as a developer.
And I believe that other developers need this feature too.
I will make very clear to them, so the package will be more usable.
I will try to do my best to represent the package in the README.md file.
Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants