Skip to content

Commit 933a182

Browse files
committed
Improve home page
1 parent b65028b commit 933a182

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public class BasicDemo {
8686
}
8787
8888
}
89-
9089
```
9190
9291
Pippo launches the embedded web server (found in your classpath) and makes the application available on port `8338` (default value).

index.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,70 @@ You are not forced to use a specific template engine or an embedded web server.
1919
Also, Pippo comes with a very small footprint that makes it excellent for embedded devices (Raspberry PI for example).
2020

2121
The framework is based on Java Servlet 3.0 and requires Java 8.
22+
23+
<br>
24+
25+
**Talk is cheap. Show me the code.**
26+
27+
1) Add some routes in your application
28+
29+
```java
30+
public class BasicApplication extends Application {
31+
32+
@Override
33+
protected void onInit() {
34+
// send 'Hello World' as response
35+
GET("/", (routeContext) -> routeContext.send("Hello World"));
36+
37+
// send a file as response
38+
GET("/file", (routeContext) -> routeContext.send(new File("pom.xml"));
39+
40+
// send a json as response
41+
GET("/json", (routeContext) -> {
42+
Contact contact = createContact();
43+
routeContext.json().send(contact);
44+
});
45+
46+
// send xml as response
47+
GET("/xml", (routeContext) -> {
48+
Contact contact = createContact();
49+
routeContext.xml().send(contact);
50+
});
51+
52+
// send an object and negotiate the Response content-type, default to XML
53+
GET("/negotiate", (routeContext) -> {
54+
routeContext.xml().negotiateContentType().send(contact);
55+
});
56+
57+
// send a template as response
58+
GET("/template", (routeContext) -> {
59+
routeContext.setLocal("greeting", "Hello");
60+
routeContext.render("hello");
61+
});
62+
}
63+
64+
private Contact createContact() {
65+
return new Contact()
66+
.setId(12345)
67+
.setName("John")
68+
.setPhone("0733434435")
69+
.setAddress("Sunflower Street, No. 6");
70+
}
71+
72+
}
73+
```
74+
75+
2) Start your application
76+
77+
```java
78+
public class BasicDemo {
79+
80+
public static void main(String[] args) {
81+
Pippo pippo = new Pippo(new BasicApplication());
82+
pippo.start();
83+
}
84+
85+
}
86+
```
87+
88+
See [Getting started](/doc/getting-started.html) section for some basic information.

0 commit comments

Comments
 (0)