forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRxApp.java
More file actions
48 lines (40 loc) · 1.25 KB
/
RxApp.java
File metadata and controls
48 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package apps;
import org.jooby.Jooby;
import org.jooby.couchbase.AsyncDatastore;
import org.jooby.couchbase.Couchbase;
import org.jooby.couchbase.N1Q;
import org.jooby.json.Jackson;
import org.jooby.rx.Rx;
import com.couchbase.client.java.view.ViewQuery;
public class RxApp extends Jooby {
{
use(new Jackson());
use(new Rx());
use(new Couchbase("couchbase://localhost/beers"));
path("/api/beer", () -> {
get(req -> {
return require(AsyncDatastore.class)
.query(N1Q.from(Beer.class));
});
get("/view", req -> {
return require(AsyncDatastore.class)
.query(ViewQuery.from("dev_beers", "beers").limit(2));
});
post(req -> {
AsyncDatastore ds = req.require(AsyncDatastore.class);
Beer beer = req.body().to(Beer.class);
return ds.upsert(beer);
});
get("/:id", req -> {
return req.require(AsyncDatastore.class).get(Beer.class, req.param("id").longValue());
});
delete("/:id", req -> {
AsyncDatastore ds = req.require(AsyncDatastore.class);
return ds.remove(Beer.class, req.param("id").value());
});
});
}
public static void main(final String[] args) throws Throwable {
run(RxApp::new, args);
}
}