feat: require an extended body parser #532
Draft
+29
−134
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.
This changes
extended
to be settable to a custom body parser, orfalse
.When
false
, the simple parser (node:querystring
) will be used which supports the following syntax:foo=a&foo=b
becomes{"foo":["a","b"]}
foo=bar
becomes{"foo":"bar"}
Otherwise, it must be a function which parses the given string:
This way the library no longer enforces a specific query string parser, but instead pushes the user to bring their own.
Most users will be fine with
URLSearchParams
, so it may make sense for us to implement a very basic conversion of that to a plain object (like in the example above).If anyone wants more than that, they can bring their own library and pass it in.
Notes:
extended
. Rather we would introduce something else I think, likebodyParser
URLSearchParams
to object parse function which becomes the default, or just usenode:querystring
(no object nesting)cc @wesleytodd this is what i was trying to explain in my comments elsewhere in the other PR. i don't think
body-parser
should be shipping with a query string parser since it may not always be enabled (so would be a waste). I think we should have a very basic nested parser or none at alli did this to explain to you what was in my head. if its the totally opposite direction of whats in yours, please feel free to discard the PR. i'll leave it as draft meanwhile