Skip to content

Commit f93d78a

Browse files
committed
Resolve #54
1 parent 8ea3ea6 commit f93d78a

19 files changed

+73
-78
lines changed

_posts/2015-03-17-getting-started.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,31 @@ public class BasicApplication extends Application {
2020
@Override
2121
protected void onInit() {
2222
// send 'Hello World' as response
23-
GET("/", (routeContext) -> routeContext.send("Hello World"));
23+
GET("/", routeContext -> routeContext.send("Hello World"));
2424

2525
// send a file as response
26-
GET("/file", (routeContext) -> routeContext.send(new File("pom.xml"));
26+
GET("/file", routeContext -> routeContext.send(new File("pom.xml"));
2727

2828
// send a json as response
29-
GET("/json", (routeContext) -> {
29+
GET("/json", routeContext -> {
3030
Contact contact = createContact();
3131
routeContext.json().send(contact);
3232
});
3333

3434
// send xml as response
35-
GET("/xml", (routeContext) -> {
35+
GET("/xml", routeContext -> {
3636
Contact contact = createContact();
3737
routeContext.xml().send(contact);
3838
});
3939

4040
// send an object and negotiate the Response content-type, default to XML
41-
GET("/negotiate", (routeContext) -> {
41+
GET("/negotiate", routeContext -> {
42+
Contact contact = createContact();
4243
routeContext.xml().negotiateContentType().send(contact);
4344
});
4445

4546
// send a template as response
46-
GET("/template", (routeContext) -> {
47+
GET("/template", routeContext -> {
4748
routeContext.setLocal("greeting", "Hello");
4849
routeContext.render("hello");
4950
});

_posts/2015-03-17-locals.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Locals are good for storing variables for the __CURRENT__ request/response cycle
1010
These variables are store in [Response]({{ site.coreurl }}/src/main/java/ro/pippo/core/Response.java) and will be available automatically to all templates for the current request/response cycle.
1111

1212
```java
13-
GET("/contact/{id}", (routeContext) -> {
13+
GET("/contact/{id}", routeContext -> {
1414
/*
1515
// variant 1 (with model)
1616
Map<String, Object> model = new HashMap<>();
@@ -33,14 +33,10 @@ Another scenario for locals:
3333

3434
```java
3535
// filter that injects 'contacts' in locals and implicit in all templates
36-
ALL("/contact.*", (routeContext) -> {
37-
routeContext.setLocal("contacts", contactService.getContacts());
38-
});
36+
ALL("/contact.*", routeContext -> routeContext.setLocal("contacts", contactService.getContacts()));
3937

4038
// just consume 'contacts' in template
41-
GET("/contacts", (routeContext) -> {
42-
routeContext.render("crud/contacts");
43-
});
39+
GET("/contacts", routeContext -> routeContext.render("crud/contacts"));
4440
```
4541

4642
The snippet for contacts template (freemarker engine) shows a list with all contacts' name:

_posts/2015-03-17-modularity.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public class ContactInitializer implements Initializer {
5757
@Override
5858
public void init(Application application) {
5959
// show contacts page
60-
application.GET("/contacts", (routeContext) -> routeContext.render("contacts"));
60+
application.GET("/contacts", routeContext -> routeContext.render("contacts"));
6161

6262
// show contact page for the contact with id specified as path parameter
63-
application.GET("/contact/{id}", (routeContext) -> routeContext.render("contact"));
63+
application.GET("/contact/{id}", routeContext -> routeContext.render("contact"));
6464
}
6565

6666
@Override
@@ -80,10 +80,10 @@ public class UserInitializer implements Initializer {
8080
@Override
8181
public void init(Application application) {
8282
// show users page
83-
application.GET("/users", (routeContext) -> routeContext.render("users"));
83+
application.GET("/users", routeContext -> routeContext.render("users"));
8484

8585
// show user page for the user with id specified as path parameter
86-
application.GET("/user/{id}", (routeContext) -> routeContext.render("user"));
86+
application.GET("/user/{id}", routeContext -> routeContext.render("user"));
8787
}
8888

8989
@Override

_posts/2015-03-17-reverse-routing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ And now the link created should be something like `/contacts/1?action=new`.
3232
The same can be applied to non controller routes:
3333

3434
```java
35-
GET("/contacts/{id}", (routeContext) -> {...}
35+
GET("/contacts/{id}", routeContext -> {...}
3636
```
3737

3838
Now we can use `uriFor(String uriPattern, Map<String, Object> parameters)` method to retrieves the URL:
@@ -48,7 +48,7 @@ Are some scenarios when it's more ease to use the route name for `uriFor()`.
4848
In few words I can add a route (in an hypothetical blog application) that render a template with:
4949
5050
```java
51-
GET("/blogs/{year}/{month}/{day}/{title}", (routeContext) -> { routeContext.render("myTemplate")});
51+
GET("/blogs/{year}/{month}/{day}/{title}", routeContext -> { routeContext.render("myTemplate")});
5252
```
5353
5454
It's hard to create the reverse routing using the `uriPattern`:
@@ -61,7 +61,7 @@ routeContext.uriFor("/blogs/{year}/{month}/{day}/{title}", parameters);
6161
The simplest solution is to add a `name` to our route and to use this name when we build the URL(reverse routing) to that route:
6262

6363
```java
64-
GET("/blogs/{year}/{month}/{day}/{title}", (routeContext) -> { routeContext.render("myTemplate")}).named("blog");
64+
GET("/blogs/{year}/{month}/{day}/{title}", routeContext -> routeContext.render("myTemplate")).named("blog");
6565
```
6666

6767
The new code becomes more short and readable:

_posts/2015-03-17-security.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ I will show you a simple implementation for a security filter.
1414

1515
```java
1616
// authentication filter
17-
GET("/contact.*", (routeContext) -> {
17+
GET("/contact.*", routeContext -> {
1818
if (routeContext.getSession("username") == null) {
1919
routeContext.setSession("originalDestination", routeContext.getRequest().getContextUriWithQuery());
2020
routeContext.redirect("/login");
@@ -24,10 +24,10 @@ GET("/contact.*", (routeContext) -> {
2424
});
2525

2626
// show contacts page
27-
GET("/contacts", (routeContext) -> routeContext.render("contacts"));
27+
GET("/contacts", routeContext -> routeContext.render("contacts"));
2828

2929
// show contact page for the contact with id specified as path parameter
30-
GET("/contact/{id}", (routeContext) -> {
30+
GET("/contact/{id}", routeContext -> {
3131
int id = routeContext.getParameter("id").toInt(0);
3232
Contact contact = (id > 0) ? contactService.getContact(id) : new Contact();
3333
routeContext.setLocal("contact", contact);
@@ -36,12 +36,10 @@ GET("/contact/{id}", (routeContext) -> {
3636
});
3737

3838
// show login page
39-
GET("/login", (routeContext) -> {
40-
response.render("login");
41-
});
39+
GET("/login", routeContext -> response.render("login"));
4240

4341
// process login submit
44-
POST("/login", (routeContext) -> {
42+
POST("/login", routeContext -> {
4543
String username = routeContext.getParameter("username").toString();
4644
String password = routeContext.getParameter("password").toString();
4745
if (authenticate(username, password)) {

_posts/2015-03-17-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class HelloWorld {
1919

2020
public static void main(String[] args) {
2121
Pippo pippo = new Pippo();
22-
pippo.GET("/", (routeContext) -> routeContext.send("Hello World!"));
22+
pippo.GET("/", routeContext -> routeContext.send("Hello World!"));
2323
pippo.start();
2424
}
2525

_posts/2015-03-17-templates.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TemplateEngine as content (for Jade the content file is _ro.pippo.jade.JadeTempl
3939
Bellow is a code snippet about how you can use a template as response to a request:
4040

4141
```java
42-
GET("/contact/{id}", (routeContext) -> {
42+
GET("/contact/{id}", routeContext -> {
4343
int id = routeContext.getParameter("id").toInt(0);
4444
String action = routeContext.getParameter("action").toString("new");
4545

@@ -54,7 +54,7 @@ Don't forget that `locals` variables from a response will be available automatic
5454
So, maybe the shortest version is:
5555

5656
```java
57-
GET("/contact/{id}", (routeContext) -> {
57+
GET("/contact/{id}", routeContext -> {
5858
routeContext.setLocal("id", routeContext.getParameter("id").toInt(0));
5959
routeContext.setLocal("action", routeContext.getParameter("action").toString("new"));
6060
routeContext.render("contact");

_posts/2015-03-17-under-the-hood.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ You can see a filter as a RouteHandler that does not commit the response. A filt
5151

5252
```java
5353
// audit filter
54-
GET("/.*", (routeContext) -> {
54+
GET("/.*", routeContext -> {
5555
Request request = routeContext.getRequest();
5656
System.out.println("Url: '" + request.getUrl());
5757
System.out.println("Uri: '" + request.getUri());
5858
System.out.println("Parameters: " + request.getParameters());
5959
});
6060

61-
GET("/hello",(routeContext) -> routeContext.send("Hello World"));
61+
GET("/hello",routeContext -> routeContext.send("Hello World"));
6262
```
6363

6464
You can see in the above example that I put an audit filter in front of all requests.
@@ -67,7 +67,7 @@ From version 0.4, Pippo comes with a new very useful method `Request.createEntit
6767
Let's see some code that shows in action this feature:
6868

6969
```java
70-
POST("/contact", (routeContext) -> {
70+
POST("/contact", routeContext -> {
7171
String action = routeContext.getParameter("action").toString();
7272
if ("save".equals(action)) {
7373
Contact contact = routeContext.createEntityFromParameters(Contact.class);
@@ -79,7 +79,7 @@ POST("/contact", (routeContext) -> {
7979
The old version has:
8080

8181
```java
82-
POST("/contact", (routeContext) -> {
82+
POST("/contact", routeContext -> {
8383
String action = routeContext.getParameter("action").toString();
8484
if ("save".equals(action)) {
8585
Contact contact = new Contact();
@@ -129,7 +129,7 @@ public class MyApplication extends Application {
129129

130130
@Override
131131
protected void onInit() {
132-
GET("/", (routeContext) -> routeContext.send("Hello World"));
132+
GET("/", routeContext -> routeContext.send("Hello World"));
133133
}
134134

135135
}
@@ -144,14 +144,14 @@ public class MyDemo {
144144
Pippo pippo = new Pippo();
145145

146146
// add routes
147-
pippo.GET("/", (routeContext) -> routeContext.send("Hello World"));
147+
pippo.GET("/", routeContext -> routeContext.send("Hello World"));
148148

149149
// start the embedded server
150150
pippo.start();
151151
}
152152

153153
}
154-
```
154+
```
155155

156156
[RouteContext]({{ site.coreurl }}/src/main/java/ro/pippo/core/route/RouteContext.java) represents the current context of a `Route` being processed by the Pippo.
157157
It's an object that encapsulates information about the route.

_posts/2015-03-17-upload.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public static void main(String[] args) {
1818
application.setUploadLocation("upload");
1919
application.setMaximumUploadSize(100 * 1024); // 100k
2020

21-
application.GET("/", (routeContext) -> routeContext.render("upload"));
21+
application.GET("/", routeContext -> routeContext.render("upload"));
2222

23-
application.POST("/upload", (routeContext) -> {
23+
application.POST("/upload", routeContext -> {
2424
// retrieves the value for 'file' input
2525
FileItem file = routeContext.getRequest().getFile("file");
2626
try {

_posts/2015-03-20-hello-world.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class HelloWorld {
1313

1414
public static void main(String[] args) {
1515
Pippo pippo = new Pippo();
16-
pippo.GET("/", (routeContext) -> routeContext.send("Hello World!"));
16+
pippo.GET("/", routeContext -> routeContext.send("Hello World!"));
1717
pippo.start();
1818
}
1919

0 commit comments

Comments
 (0)