question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simplify request parsing and validation

See original GitHub issue

From @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 it parse_XYZ.

I think it would be worth to re-evaluate the current pattern and see whether we can simplify and streamline it.

cc @jdeanwallace

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mtlynchcommented, Jan 19, 2022

Nice! Great work, @rw4nn!

1reaction
jotaencommented, Jan 19, 2022

🥳 Awesome @rw4nn, I think we’ve reached a simple and clean state now!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found