Added options to transform API event handlers #1818
+31
−7
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.
PR Checklist
Please check if your PR fulfills the following requirements:
What is the current behavior?
N/A
What is the new behavior?
Add an additional options to the server configuration to allow for HTTP endpoints to be arbitrarily modified without.
Use Cases
These are just some examples why I personally would find this useful all though there are many other applications.
Say we had some service function that includes some fairly nested function calls say something like the following example of a transaction in drizzle.
Rather than having to drill back up the errors it's nice to be able to just throw them
But we need to make sure that we are properly handling each and every endpoint, say something like so
Again though this still leads to a lot of boilerplate even if we break out this into it's own function instead we could use this new proposed API.
This would then be applied to all event handlers. Additionally it opens the door for some additional DX niceties without having to make any breaking changes by being able to modify the
APIEvent
bespoke to the application. Perhaps exposing cookies, query parameters etc more directly but that's really up to the individual applicationSome Additional Notes and Considerations
This API isn't perfect, especially taking two different options objects but that mostly stems from maintaining backwards compatibility and to only effect projects that make direct use of it. Any suggestions would be very welcome.
Notably this is distinct from middleware as we need to be able to access the transform function itself