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
Route Groups #245
Route Groups #245
Conversation
return routes; | ||
} | ||
|
||
private String buildPath(String uriPattern) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some utility methods in StringUtils
to add and remove prefix or trailing strings. Using those would simplify this method.
I think Travis fails because there is no import for |
@ScienJus thanks for your contribution. Now in my mind is something similar with: RouteGroup usersGroup = RouteGroup("/users");
GET("{id}", routeContext -> { ... }).group(usersGroup);
POST("{id}", routeContext -> { ... }).group(usersGroup);
// add more routes in this group I will reflect a little bit at this feature. |
i think we should inject slash on nested groups and remove slash if it's end of pattern. the fault tolerance will be better. like: |
@decebals it's good, you can do that when groups have more options, like:
|
@ScienJus Yes. This is the idea. I want to add more options/attributes to
Also. I see two possible API:
myGroup.addRoute(...); // or a shortcut method like 'myGroup.GET("{id}", routeContext -> { ... })'
addRouteGroup(myGroup); |
@decebals @gitblit i think one group have many child groups and many routes, so on current commit, you can use group like that:
or:
you also can use onInit method:
what do you think? |
I think that I see the light and I like what I see. 😄 I prefer to have the same API in I prefer to add the route group in So, the code can looks like: addRouteGroup(new RouteGroup("uriPattern") {
// add routes
);
or
// reduce code lines in Application with
addRouteGroup(new UserGroup());
addRouteGroup(new ContactGroup()); I don't like to add I prefer to preserve I don't think that we need That is my correction to the last comment of @ScienJus |
… RouteGroup. constructor
@decebals .i agree that i use i have a question about
then i modify |
I see that I prefer to rename I will make some comments on you code |
@@ -268,6 +270,13 @@ public void addRoute(Route route) { | |||
getRouter().addRoute(route); | |||
} | |||
|
|||
public void addGroup(RouteGroup routeGroup) { | |||
routeGroup.getRoutes().forEach(this::addRoute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new method addRouteGroup
in Router
interface, call getRouter().addRouteGroup()
here and move the implementation in DefaultRouter
. The idea is that I want to add the tests in Router.
That is all. |
@decebals another question, do we need some methods to remove route from group or remove group from group or remove group from application? |
@@ -33,26 +33,30 @@ | |||
* | |||
* @return the context path | |||
*/ | |||
public String getContextPath(); | |||
String getContextPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this modification?
I understand you. I prefer to put public also for all methods in an interface. For the future it's a good practice to not touch the code if we don't add something new or if not fix a very bad formatted code. I will change minor things after I merge this PR. Thanks very much for this important PR! |
👍 Cool. Route groups will be pretty handy and give Pippo a little more flexibility in app config. Nice job. |
Before:
After:
I think it's better
ps: i pulled into a wrong branch?