Closed wildonion closed 4 months ago
Although there are concepts similar to Controller in many web frameworks, I don't think it's necessary to introduce such a concept.
I think Controller is just doing the same function as namespace in most cases. There's no need to introduce two concepts for one thing.
This design seems to save some code in some cases, but in fact, it makes things more complicated. For example, what if the function name is inconsistent with the route path to be registered? How to add middleware? It makes things inflexible and introduces more complex problems while trying to simplify the code.
@chrislearn
thanks for your response, yes you're right although there are solutions to forementioned problems like if we could add a custom attribute like #[handler(path="/user/get/<id>/")]
and extend the method name in macro handler, the inconsistency problem can be solved or for the middleware issue, a proc macro like #[hoop]
or #[middleware]
can be used for that then when we're registering the controller the parser will separate each of them to push them into the main router to build the router tree, but as you've mentioned indeed more complex logics behind the framework needs to get handled.
As mentioned above, the fact that you want to create multiple complex macros requires a learning cost and no flexibility, but, what benefits do you get? Nothing.
I hope you guys are doing well, thanks for this great fremework, the routing system is a great feature simplifies handling api logics a lot, however I have couple of ideas in the mind want to share with you, wondering if we could implement them in future versions. one of them is writing structure based conrollers, currently as I'm designing the apis there is this pattern of
#[handler]
that can be added to theimpl
of structure but there is a lock of supporting of adding it on top of structure methods like if we could implement the following logic or similar to that would be a great option:or
and the registeration would be something like passing the structure to a method like
register()
:actually this pattern helps a lot in designing api and adds more flexibility to the current router system, in fact