Simplify request parsing and validation
See original GitHub issueFrom @mtlynch - We’re going to fix this for existing parsers, but in the meantime, we’re not going to add new validators. We’ll just do parsing and validating in the same place.
The request_parsers
package contains logic that’s mostly concerned with extracting data from a JSON payload. The validation of the data is split off into a sub-package validators
.
- Both the implementation and the tests of the request parsers are quite repetitive, while the parsing logic in itself is rather trivial.
- The fact that we keep parsing and validating separately, “forces” us to write redundant tests. See e.g. the video settings, where the same logic is tested in both the parser and the validator.
- The request parsing tests all have their own definition of
make_mock_request
, which we have 7 identical copies of in Pro. - We are not consistent with the code style: in some cases, we just call it
parse
, whereas in others we call itparse_XYZ
.
I think it would be worth to re-evaluate the current pattern and see whether we can simplify and streamline it.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Parsing & Validating JSON in Flask Requests - Arunmozhi
This post only exposes the basic implementation of using the libraries and simplifying parsing and validation of incoming JSON. The marshmallow ...
Read more >Parse, don't validate - Alexis King
Parsing, not validating, in practice · Use a data structure that makes illegal states unrepresentable. Model your data using the most precise ...
Read more >Possibility to authenticate after parsing and before validation?
get the raw body and attach to the request; set a custom content ... I'm wondering if a hook between parsing and validation...
Read more >Using Marshmallow for HTTP Request Body JSON parsing ...
In this video, we'll see how to use Marshmallow to validate the HTTP request JSON body. Marshmallow is a serialization/deserialization ...
Read more >Using JSON Schema to Validate Web Service Requests
Create a data-transfer object (DTO) or a domain object from the JSON input. This approach also uses an ObjectMapper, to which you then...
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
Nice! Great work, @rw4nn!
🥳 Awesome @rw4nn, I think we’ve reached a simple and clean state now!