feat(request): add get_param_as_media() method #2556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Adds a new public helper:
Request.get_param_as_media(name, media_type=None, required=False, store=None, default=None):1- Deserializes a single query-string parameter using the app's configured media handlers.
2- If media_type is omitted, falls back to the app's
default_media_type.3- Stores the parsed value in
storewhen provided.4- Raises
HTTPInvalidParamon parse errors (or when no suitable handler exists for non-JSON media).ASGI support:
1-
falcon.asgi.Request.get_param_as_mediadelegates to the synchronous WSGI implementation (parameter values are already in memory).2-
get_param_as_json()now delegates toget_param_as_media(..., MEDIA_JSON)(thin wrapper).Related Issues
closes: #2549
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. Reading our contribution guide at least once will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
tox.docs/.docs/.versionadded,versionchanged, ordeprecateddirectives.docs/_newsfragments/, with the file name format{issue_number}.{fragment_type}.rst. (Runtox -e towncrier, and inspectdocs/_build/html/changes/in the browser to ensure it renders correctly.)If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.