-
-
Notifications
You must be signed in to change notification settings - Fork 752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Dynamic Method Definitions #3339
base: dove
Are you sure you want to change the base?
Conversation
Thank you for putting this together. Here are some of my initial thoughts/questions:
|
I'm not 100% married to the custom routes being supported, but it's a useful option to expose, and gives developers more flexibility in their options of implementing things. |
My 2 cents: The limitation mainly comes from having a method signature fixed to To modify this behavior without being too invasive we could define the methods as follows: methods: [
'get',
['myCustomMethod', ['id', 'data', 'params']]
] If the custom method uses a signature other than |
Summary
I started this refactor a while ago and had to pause it after the scope blew out. I thought I might put up a PR to get feedback before dedicating any further time to it.
One of the notable limitations of custom methods is that they are limited to POST requests with data only:
I initially brought this up a while ago and got push-back (mainly for the last example) as actions in the route goes against the HTTP spec. Whilst technically correct, I'd also argue that exactly following the spec isn't always up to us or the developer, a lot of people don't follow this spec when doing api design, and actively making that more difficult hurts the framework. Ultimately it's up to the person implementing the method to decide if they are going to follow the spec.
Currently you tell the service to expose methods via the
methods
field in theServiceOptions
. This array only accepts strings, allowing no further configuration on a per-method basis. This PR gives the ability to instead pass a MethodDefinition object, where you can specify a more advanced use-case, whilst also still accepting a string which will default to the current functionality.A lot of the blow-out in the scope of this is removing hard-coded references to the default methods and instead dynamically driving off of the definitions. Although I think making this switch will benefit in the long run. My main objective was to make custom methods more of a primary feature rather than an afterthought.
Still some things that need to be done that I can remember:
packages/transport-commons/src/client.ts