Skip to content

Commit aa5252c

Browse files
committed
Fix #26
1 parent ee3d179 commit aa5252c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

_posts/2015-05-05-routes.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,49 @@ GET("/contact/{id}(\\.(json|xml|yaml))", (ctx) -> ctx.send(contact));
103103
**Note:**
104104

105105
If you specify your parameter <u>without</u> a regex pattern, like the third example (e.g. `{id}`), the value of *id* will include your suffix unless you require the suffix using the pattern in the second example.
106+
107+
#### Route groups
108+
109+
[RouteGroup]({{ site.coreurl }}src/main/java/ro/pippo/core/route/RouteGroup.java) allow you to prefix <code>uriPattern</code>,
110+
across a large number of routes without needing to define this attribute on each individual route.
111+
Also you can add (route) filters for all routes of the group.
112+
113+
The below snippet defines a `UserRoutes` group:
114+
115+
```java
116+
public class UserRoutes extends RouteGroup {
117+
118+
public UserRoutes() {
119+
super("/user");
120+
121+
// BEFORE FILTERS
122+
addBeforeFilters();
123+
124+
// CRUD ROUTES
125+
GET("/{id}", routeContext -> { ... }); // retrieve
126+
POST("/", routeContext -> { ... }); // create
127+
PUT("/{id}", routeContext -> { ... }); // update
128+
DELETE("/{id}", routeContext -> { ... }); // delete
129+
}
130+
131+
}
132+
```
133+
134+
Add the `UserRoutes` group to application:
135+
136+
```java
137+
public class PippoApplication extends Application {
138+
139+
@Override
140+
protected void onInit() {
141+
addRouteGroup(new UserRoutes());
142+
}
143+
144+
}
145+
```
146+
147+
You can access the routes defined in `UserRoutes` using something like `http://localhost:8338/user/1` (retrieve the user with _id_ equals with 1).
148+
149+
You can see a more complex example in [Matilda](https://github.com/decebals/matilda/blob/master/src/main/java/ro/fortsoft/matilda/PippoApplication.java#L108) (a real life application built with Pippo).
150+
151+

0 commit comments

Comments
 (0)