Skip to content

Named route group #253

Description

@decebals

The idea is that we add a new named method on RouteGroup similar with the same method from Route.

Show me the code:

// create the group with a name
RouteGroup group = new RouteGroup("/users").named("users.");

// add routes for group
group.GET("/", ...).named("getAll");
group.GET("/{id}", ...).named("get");
group.PUT("/{id}", ...).named("update");
group.DELETE("/{id}", ...).named("delete");

// add route group to application
addRouteGroup(group);

The idea is that the route name is prefixed automatically with the group name.
Now, you may use the route's name when generating URLs or redirects:

Map<String, Object> parameters = ...
routeContext.uriFor("users.getAll", parameters);
routeContext.uriFor("users.get", parameters);
routeContext.uriFor("users.update", parameters);
routeContext.uriFor("users.delete", parameters);
// the same for redirect
routeContext.redirect("users.getAll", parameters);
...

In my example I used . as separator but you can use any character or string.

What you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions