You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Routes in Pippo are created using methods named after HTTP verbs. For instance, in the previous example, we created a route to handle GET requests to the root of the website. You have a corresponding method in Application for all commonly used HTTP verbs (GET, POST, DELETE, HEAD, PUT). For a basic website, only GET and POST are likely to be used.
28
+
Routes in Pippo are created using methods named after HTTP verbs. For instance, in the previous example, we created a route to handle GET requests to the root of the website. You have a corresponding method in Application for all commonly used HTTP verbs (__GET__, __POST__, __DELETE__, __HEAD__, __PUT__, __PATCH__, __CONNECT__ and __OPTIONS__). For a basic website, only GET and POST are likely to be used.
29
+
Pippo comes with a "pseudo" verb `ANY` that meant the route applied to all HTTP methods/verbs.
30
+
```java
31
+
ANY("/example", newCSRFHandler());
32
+
```
29
33
30
34
The route that is defined first takes precedence over other matching routes. So the ordering of routes is crucial to the behavior of an application.
31
35
32
36
Each defined route has an __urlPattern__.
33
37
The route can be static or dynamic:
34
38
35
39
-`static` ("/", "/hello", "/contacts/1")
36
-
-`dynamic` (regex: "/.*" or parameterized: "/contact/{id}", "/contact/{id: [0-9]+}")
As you can see, it's easy to create routes with parameters. A parameter is wrapped by curly braces `{name}` and can optionally specify a regular expression.
39
45
40
46
You can retrieve the path parameter value for a request in type safe mode using:
41
47
42
48
```java
43
49
GET("/contact/{id}", routeContext -> {
50
+
// retrieve some parameters from request
44
51
int id = routeContext.getParameter("id").toInt(0);
Now, if you type `localhost/test` or `localhost/test/` in browser, the result is the same.
98
+
60
99
#### Named routes
61
100
62
101
`Named` routes make referring to routes when generating redirects or URLs more convenient. You may specify a name for a route like so:
@@ -184,4 +223,4 @@ In above snippet I added (in DemoApplication) `AdminRoutes` as route group which
184
223
I don't need to know when I create a RouteGroup where the group will be mount. For example I can have a modular web application where each plugin comes with own independent routes (user management -> `UserRoutes`, customer management -> `CustomerRoutes`).
185
224
186
225
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).
0 commit comments