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
{{ message }}
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
@@ -198,13 +201,13 @@ API is short and easy to learn, around 30 classes.
198
201
The most notable classes are: [Jooby.Module], [Route] and [WebSocket].
199
202
200
203
### dependencies
201
-
*[Jetty](https://www.eclipse.org/jetty/)as HTTP NIO Web Server
204
+
*[Jetty](https://www.eclipse.org/jetty/)for HTTP NIO Web Server
202
205
*[Guice](https://github.com/google/guice) for Dependency Injection
203
-
*[Config](https://github.com/typesafehub/config) for a powerful config system
206
+
*[Config](https://github.com/typesafehub/config) for configuration management
204
207
205
208
Jooby is organized as a set of reusable modules (a.k.a middleware in [Express](http://expressjs.com/)).
206
-
A module does as minimum as possible and it should NOT make strong/hard decisions for you, or when it does, it must be 100% configurable.
207
-
For example, a module for the popular [Hibernate]() library should do:
209
+
A module should do as minimum as possible and it should NOT make strong/hard decisions for you, or when it does, it must be 100% configurable.
210
+
For example, a module for the popular [Hibernate]() library should:
208
211
209
212
1) create a session factory
210
213
@@ -218,30 +221,30 @@ but NOT:
218
221
219
222
2) wrap Hibernate API or similar
220
223
221
-
If a module does as minimum as possible, developers have the power! of setup/configure or take real advantage of native library features without noise.
224
+
If a module does as minimum as possible, developers have the power! of setup/configure and take real advantage of native library features without noise.
222
225
223
226
224
227
## routes
225
228
226
229
Like in [Express](http://expressjs.com/) routes can be chained/stacked and executed in the same order they are defined.
227
230
228
-
A route is represent by [Route] and there are two types of handlers: [Router] and [Filter].
231
+
A route is represent by [Route] and there are two types of handlers: [Route.Handler] and [Route.Filter].
229
232
230
233
A handler is basically the callback executed while a route is the whole thing: verb, path, handler, etc...
231
234
232
235
233
236
```java
234
237
{
235
-
get("/", (req, res) ->
238
+
get("/", (req, rsp) ->
236
239
log.info("first")
237
240
);
238
241
239
-
get("/", (req, res) ->
242
+
get("/", (req, rsp) ->
240
243
log.info("second")
241
244
);
242
245
243
-
get("/", (req, res) ->
244
-
res.send("last")
246
+
get("/", (req, rsp) ->
247
+
rsp.send("last")
245
248
);
246
249
}
247
250
```
@@ -284,13 +287,13 @@ In addition to Ant-style path pattern, variables pattern are also possible:
284
287
285
288
```java
286
289
{
287
-
get("/users/:id", (req, res) ->
288
-
res.send(req.param("id").stringValue())
290
+
get("/users/:id", (req, rsp) ->
291
+
rsp.send(req.param("id").stringValue())
289
292
);
290
293
291
294
// or with braces
292
-
get("/users/{id}", (req, res) ->
293
-
res.send(req.param("id").stringValue())
295
+
get("/users/{id}", (req, rsp) ->
296
+
rsp.send(req.param("id").stringValue())
294
297
);
295
298
}
296
299
```
@@ -305,9 +308,9 @@ Inline routes use lambdas and are useful for quickstart and/or small/simple appl
305
308
306
309
```java
307
310
{
308
-
get("/", (req, res) ->res.send(req.path()));
311
+
get("/", (req, rsp) ->rsp.send(req.path()));
309
312
310
-
post("/", (req, res) ->res.send(req.path()));
313
+
post("/", (req, rsp) ->rsp.send(req.path()));
311
314
312
315
... etc...
313
316
}
@@ -323,10 +326,10 @@ External routes are declared in a separated class and looks like:
A websocket is listen at ```/```. The path can be as simple or complex as you need:
519
+
520
+
```java
521
+
"/user/:id"
522
+
"/events/*"
523
+
"/events/**/*"
524
+
etc...
525
+
```
526
+
527
+
The socket callback will be executed everytime a client is connected. From there you can send messages, listen for messages, or errors.
528
+
529
+
### data types
530
+
531
+
```java
532
+
ws("/", (socket) -> {
533
+
534
+
socket.onMessage(message -> {
535
+
// client sent a JSON formatted message and it is parsed as MyObject
536
+
MyObject object = message.to(MyObject.class);
537
+
});
538
+
539
+
MyObject value =...;
540
+
// MyObject will be serialized as JSON
541
+
socket.send(value);
542
+
})
543
+
.consumes("application/json")
544
+
.produces("application/json");
545
+
```
546
+
547
+
Please note that consumes/produces don't do content negotiation (like they do in routes). On WebSockets they are used to choose/pick a body (de)serializer.
548
+
549
+
550
+
For more information checkout the [WebSocket doc]()
0 commit comments