|
| 1 | += Welcome to Jooby! |
| 2 | +:doctype: book |
| 3 | +:title: Jooby: do more! more easily!! |
| 4 | +:toc: left |
| 5 | +:toclevels: 3 |
| 6 | +:sectanchors: |
| 7 | +:sectlinks: |
| 8 | +:sectnums: |
| 9 | +:linkattrs: |
| 10 | +:icons: font |
| 11 | +:source-language: asciidoc |
| 12 | +:imagesdir: images |
| 13 | +:source-highlighter: highlightjs |
| 14 | +:highlightjs-theme: agate |
| 15 | +:favicon: images/favicon96.png |
| 16 | +:joobyVersion: 2.0.0-Alpha1 |
| 17 | +:love: ❤ |
| 18 | + |
| 19 | +//// |
| 20 | +Style guidelines: |
| 21 | + |
| 22 | +* Refer to the project in prose as simply Jooby, with no adornment or formatting. Enclose the class |
| 23 | + name `Jooby` in back ticks so readers can distinguish references to the `Jooby` class from |
| 24 | + references to the Jooby project as a whole. |
| 25 | +* 100 characters per line, except when you can't break it up e.g. links or asciidoc directives |
| 26 | +* Avoid class definition on Jooby code examples. Always start an example with `{...}` |
| 27 | +* Avoid JUnit boilerplate in code examples. Assertions are ok if they complement the example. |
| 28 | +* External links should use a caret at the end of the link title e.g. |
| 29 | + link:path/to/doc[the title^] so they open in separate tabs. See |
| 30 | + http://asciidoctor.org/docs/asciidoc-writers-guide/#target-window-and-role-attributes-for-links |
| 31 | +* Be funny. Nobody like reading dry documentation. |
| 32 | +* Be inclusive: keep usage of male and female names equal in code examples. |
| 33 | +* Best edited while drunk |
| 34 | +
|
| 35 | +//// |
| 36 | + |
| 37 | +== Introduction |
| 38 | + |
| 39 | +Jooby is a modern, fun and easy to use web framework for Java built on top of your favorite web server. |
| 40 | + |
| 41 | +.App.java |
| 42 | +[source,java] |
| 43 | +---- |
| 44 | +public class App extends Jooby { // <1> |
| 45 | +
|
| 46 | + { |
| 47 | + get("/", ctx -> { // <2> |
| 48 | + return "Hello Jooby"; // <3> |
| 49 | + }); |
| 50 | + } |
| 51 | +
|
| 52 | + public static void main(String[] args) { |
| 53 | + run(App::new, args); // <4> |
| 54 | + } |
| 55 | +} |
| 56 | +---- |
| 57 | +<1> Create a new instance of `Jooby` |
| 58 | +<2> Define a route. A route consist of: a `HTTP method`, a `path pattern` and `handler` function |
| 59 | +<3> Returns `Hello Jooby` to the client |
| 60 | +<4> Initialize and run `App.java` |
| 61 | + |
| 62 | +=== Status |
| 63 | + |
| 64 | +[IMPORTANT] |
| 65 | +==== |
| 66 | +There is no stable release yet for `2.0.0`. API may change between `alpha/beta` releases without |
| 67 | +warning. |
| 68 | +
|
| 69 | +This is a **work-in-progress** document and contains documentation and examples of what is ready to use. If it is not documented here, it is not implemented. |
| 70 | +
|
| 71 | +Not ready to play yet? Try https://jooby.org[Jooby 1.x] |
| 72 | +
|
| 73 | +Thank you {love} |
| 74 | +==== |
| 75 | + |
| 76 | +=== Micro and Fullstack |
| 77 | + |
| 78 | +Jooby is a modular micro framework. At the core level: |
| 79 | + |
| 80 | +- Reflection and annotation free |
| 81 | +- No dependency injection |
| 82 | +- Only HTTP Routing |
| 83 | +- Multi Server: link:server/jetty.html[Jetty], Netty, Undertow |
| 84 | + |
| 85 | +Now, if you need more... Jooby don't leave you alone: |
| 86 | + |
| 87 | +- Dependency injection via https://github.com/google/guice[Guice] |
| 88 | +- MVC programming model (subset of https://github.com/jax-rs[JAX-RS]) |
| 89 | +- Extensive module ecosytem |
| 90 | + |
| 91 | +=== Script API |
| 92 | + |
| 93 | +Script API (a.k.a script routes) provides a fluent DSL, reflection and annotation free based on `lambda` functions. |
| 94 | + |
| 95 | +We usually extends `Jooby` and define routes in the instance initializer: |
| 96 | + |
| 97 | +.App.java |
| 98 | +[source,java] |
| 99 | +---- |
| 100 | +public class App extends Jooby { |
| 101 | +
|
| 102 | + { |
| 103 | + get("/", ctx -> { |
| 104 | + return "Hello Jooby"; |
| 105 | + }); |
| 106 | + } |
| 107 | +
|
| 108 | + public static void main(String[] args) { |
| 109 | + run(App::new, args); |
| 110 | + } |
| 111 | +} |
| 112 | +---- |
| 113 | + |
| 114 | +This is not strictly necessary (of course), you may instantiate `Jooby` like: |
| 115 | + |
| 116 | +.App.java |
| 117 | +[source,java] |
| 118 | +---- |
| 119 | +public class App { |
| 120 | +
|
| 121 | + public static void main(String[] args) { |
| 122 | + run(() -> { |
| 123 | + Jooby app = new Jooby(); |
| 124 | +
|
| 125 | + app.get("/", ctx -> { |
| 126 | + return "Hello Jooby"; |
| 127 | + }); |
| 128 | + }, args); |
| 129 | + } |
| 130 | +} |
| 131 | +---- |
| 132 | + |
| 133 | +=== MVC API |
| 134 | + |
| 135 | +MVC API (a.k.a mvc routes) on the other hand uses annotation and reflection to define routes. Jooby |
| 136 | +implements a subset of https://github.com/jax-rs[JAX-RS] and it is not intended to be a fully |
| 137 | +https://github.com/jax-rs[JAX-RS] compliant. |
| 138 | + |
| 139 | +.App.java |
| 140 | +[source,java] |
| 141 | +---- |
| 142 | +public class App { |
| 143 | +
|
| 144 | + { |
| 145 | + use(new MyController()); |
| 146 | + } |
| 147 | +
|
| 148 | + public static void main(String[] args) { |
| 149 | + run(App::new, args); |
| 150 | + } |
| 151 | +} |
| 152 | +---- |
| 153 | + |
| 154 | +.MyController.java |
| 155 | +[source,java] |
| 156 | +---- |
| 157 | +public class MyController { |
| 158 | +
|
| 159 | + @GET |
| 160 | + public String hello() { |
| 161 | + return "Hello Jooby"; |
| 162 | + } |
| 163 | +} |
| 164 | +---- |
| 165 | + |
| 166 | +[NOTE] |
| 167 | +==== |
| 168 | +MVC API is not implemented yet. |
| 169 | +==== |
| 170 | + |
| 171 | +include::getting-started.adoc[] |
| 172 | + |
| 173 | + |
| 174 | + |
0 commit comments