-
-
Notifications
You must be signed in to change notification settings - Fork 828
More flexible server fn macro api #3725
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
More flexible server fn macro api #3725
Conversation
|
Nice work on the changes, I can see how this can become even more flexible. I'll have to see what changes are made to defining codecs so that we can bring leptos-use and the codee crate it uses along for the ride. I have no problem with changing the generated API routes or restricting to StrLiteral, unless someone is doing something truly cursed or relying on API routes which we don't guarantee it should be good to go |
|
@benwis At the moment codee codecs are only used in Resources but not server functions. They implement their own with constructing a Request/Response directly. Are you suggesting to use codee codecs here as well? It could be done rather easily and I'd be happy to submit a PR. |
I was perhaps under the mistaken impression that codee codecs applied to server fns, since most of the obvious use cases for Resources for me involve using Resources with them. But overall yes, I can't see a reason why people wouldn't use codee codecs in this way. Especially now that we seem to be uncoupling input and output encodings and making some other changes. @ealmloff Does this or could this also support selection of input and output HTTP verbs? I know we now have a protocol selector, so I think it's worth investigating that and differing protocols on the input/output side |
|
If I understand this correctly then codee could be used to convert from/to strings which is kind of orthogonal to the rest of the request/response in terms of verbs and headers. This would still be handled directly by the server function crate. |
Yes, the protocol API added in #3656 controls the request and response together but you can still use |
|
@ealmloff I think this is ready for merging, are you happy with it? |
Yes, this will make the dioxus server fn macro much easier to maintain |
This PR refactors the server function macro implementation into a struct that can be parsed and converted to tokens. The struct has more modular methods for derived values like the protocol based on the default configuration and the parsed arguments. This should make it both easier to maintain in the long run and easier to modify for Dioxus. I did make some fields of the server function arguments and body public to make them easier to read and modify externally. This introduces some additional semvar requirements. I have marked the newly public structs as non exhaustive so we can add fields in minor releases. Let me know if you would rather expose getters and setters or if the API surface is too broad
There are two small potentially breaking changes in this PR:
prefixnow only acceptStrLitinstead of anyLiteral. This makes parsing the contents easier since we don't need to rely on the display implementation and strip the quotes manually.