Skip to content

Commit 2f3f519

Browse files
committed
Kotlin coroutine: unify normal router and move coroutine version to his own router
1 parent 12af57f commit 2f3f519

31 files changed

+325
-228
lines changed

docs/asciidoc/body.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ Raw `request body` is available via javadoc:Context[body] method:
2727
[source,kotlin,role="secondary"]
2828
----
2929
{
30-
post("/string") { ctx ->
30+
post("/string") {
3131
val body = ctx.body().value() // <1>
3232
...
3333
}
3434
35-
post("/bytes") ctx -> {
35+
post("/bytes") {
3636
val body = ctx.body().bytes() // <2>
3737
...
3838
}
3939
40-
post("/stream") { ctx ->
40+
post("/stream") {
4141
val body = ctx.body().stream() // <3>
4242
...
4343
}
@@ -97,7 +97,7 @@ and returns a single result of the given type.
9797
lib.fromJson(body, type) // <4>
9898
}
9999
100-
post("/") { ctx ->
100+
post("/") {
101101
val myObject = ctx.body<MyObject>() // <5>
102102
}
103103
}
@@ -143,7 +143,7 @@ Response body is generated from `handler` function:
143143
[source, kotlin,role="secondary"]
144144
----
145145
{
146-
get("/") { ctx ->
146+
get("/") {
147147
ctx.responseCode = 200 // <1>
148148
149149
ctx.responseType = MediaType.text // <2>
@@ -212,7 +212,7 @@ produces a result.
212212
json // <5>
213213
}
214214
215-
get("/item") { ctx ->
215+
get("/item") {
216216
val myObject = ...;
217217
myObject // <6>
218218
}

docs/asciidoc/context.adoc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ response.
3535
[source, kotlin, role="secondary"]
3636
----
3737
{
38-
get("/") { ctx ->
38+
get("/") {
3939
val token = ctx.header("token").value() // <1>
4040
4141
val headers = ctx.headers() // <2>
@@ -74,7 +74,7 @@ Request cookies are send to the server using the `Cookie` header, but we do prov
7474
[source, kotlin, role="secondary"]
7575
----
7676
{
77-
get("/") { ctx ->
77+
get("/") {
7878
val token = ctx.cookie("token").value() // <1>
7979
8080
val = ctx.cookieMap(); // <2>
@@ -111,15 +111,15 @@ Path parameter are part of the `URI`. To define a path variable you need to use
111111
[source,kotlin,role="secondary"]
112112
----
113113
{
114-
get("/{id}") { ctx -> ctx.path("id").value() } // <1>
114+
get("/{id}") { ctx.path("id").value() } // <1>
115115
116-
get("/@{id}") { ctx -> ctx.path("id").value() } // <2>
116+
get("/@{id}") { ctx.path("id").value() } // <2>
117117
118-
get("/file/{name}.{ext}") { ctx -> cxt.path("name") + "." + ctx.path("ext") } // <3>
118+
get("/file/{name}.{ext}") { cxt.path("name") + "." + ctx.path("ext") } // <3>
119119
120-
get("/file/*") { ctx -> ctx.path("*") } // <4>
120+
get("/file/*") { ctx.path("*") } // <4>
121121
122-
get("/{id:[0-9]+}") { ctx -> ctx.path("id) } // <5>
122+
get("/{id:[0-9]+}") { ctx.path("id) } // <5>
123123
}
124124
----
125125

@@ -151,7 +151,7 @@ Path parameter are part of the `URI`. To define a path variable you need to use
151151
[source, kotlin, role="secondary"]
152152
----
153153
{
154-
get("/{name}") { ctx ->
154+
get("/{name}") {
155155
val pathString = ctx.pathString() // <1>
156156
157157
val path = ctx.path() // <2>
@@ -226,7 +226,7 @@ class SearchQuery {
226226
[source, kotlin, role="secondary"]
227227
----
228228
{
229-
get("/search") { ctx ->
229+
get("/search") {
230230
val queryString = ctx.queryString() // <1>
231231
232232
val query = ctx.query() // <2>
@@ -316,7 +316,7 @@ class User {
316316
[source, kotlin, role="secondary"]
317317
----
318318
{
319-
post("/user") { ctx ->
319+
post("/user") {
320320
val form = ctx.form() // <1>
321321
322322
val formMap = ctx.formMultimap() // <2>
@@ -390,7 +390,7 @@ class User {
390390
[source, kotlin, role="secondary"]
391391
----
392392
{
393-
post("/user") { ctx ->
393+
post("/user") {
394394
val multipart = ctx.multipart() // <1>
395395
396396
val multipartMap = ctx.multipartMultimap() // <2>
@@ -474,7 +474,7 @@ a javadoc:Session[] but the lifecycle is shorter: *data is kept for only one req
474474
.Kotlin
475475
[source,kotlin,role="secondary"]
476476
----
477-
get("/") {ctx ->
477+
get("/") {
478478
ctx.flash("success").value("Welcome!") <3>
479479
}
480480

docs/asciidoc/di-dagger.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fun main(args: Array<String>) {
7878
val dagger = DaggerAppComponent.builder() <1>
7979
.build()
8080
81-
get("/") { ctx ->
81+
get("/") {
8282
val service = dagger.getMyService() <2>
8383
service.doSomething()
8484
}

docs/asciidoc/di-guice.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fun main(args: Array<String>) {
4141
runApp(args) {
4242
install(Guiceby()) <1>
4343
44-
get ("/") { ctx ->
44+
get ("/") {
4545
val service = require(MyService::class) <2>
4646
service.doSomething()
4747
}

docs/asciidoc/di-spring.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ import io.jooby.di.Spring
4343
fun main(args: Array<String>) {
4444
runApp(args) {
4545
46-
install(new Springby()) <2>
46+
install(Spring()) <2>
4747
48-
get ("/") { ctx ->
48+
get ("/") {
4949
val service = require(MyService::class) <3>
5050
service.doSomething()
5151
}

docs/asciidoc/di-weld.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fun main(args: Array<String>) {
4141
runApp(args) {
4242
install(Weldby()) <1>
4343
44-
get ("/") { ctx ->
44+
get ("/") {
4545
val service = require(MyService::class) <2>
4646
service.doSomething()
4747
}

docs/asciidoc/execution-model.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import io.jooby.Jooby.runApp
4444
4545
fun main(args: Array<String>) {
4646
runApp(args, EVENT_LOOP) {
47-
get("/") { ctx -> "I'm non-blocking!" }
47+
get("/") { "I'm non-blocking!" }
4848
}
4949
}
5050
----
@@ -97,14 +97,14 @@ import io.jooby.Jooby.runApp
9797
fun main(args: Array<String>) {
9898
runApp(args, EVENT_LOOP) {
9999
100-
get("/") { ctx ->
100+
get("/") {
101101
"I'm non-blocking!"
102102
}
103103
104104
dispatch {
105105
// All the routes defined here are allowed to block:
106106
107-
get("/db-list") { ctx ->
107+
get("/db-list") {
108108
/** Safe to block! */
109109
val result = ...; // Remote service, db call, etc..
110110
result
@@ -212,7 +212,7 @@ import io.jooby.Jooby.runApp
212212
fun main(args: Array<String>) {
213213
runApp(args, WORKER) {
214214
215-
get("/") { ctx ->
215+
get("/") {
216216
/** Safe to block! */
217217
val result = ...;// Remote service, db call, etc..
218218
result
@@ -258,7 +258,7 @@ fun main(args: Array<String>) {
258258
259259
worker(Executors.newCachedThreadPool())
260260
261-
get("/") { ctx ->
261+
get("/") {
262262
/** Safe to block from cached thread pool! */
263263
val result = ...;// Remote service, db call, etc..
264264
result
@@ -321,12 +321,12 @@ import io.jooby.Jooby.runApp
321321
322322
fun main(args: Array<String>) {
323323
runApp(args) {
324-
get("/non-blocking") { ctx ->
324+
get("/non-blocking") {
325325
CompletableFuture
326326
.supplyAsync { "I'm non-blocking!" } // <1>
327327
}
328328
329-
get("/blocking") { ctx ->
329+
get("/blocking") {
330330
"I'm blocking" // <2>
331331
}
332332
}

docs/asciidoc/extension.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class App: Kooby({
7777
7878
install(MyExtension()) <1>
7979
80-
get("/") {ctx ->
80+
get("/") {
8181
val ds = require(MyDataSource::class) <2>
8282
}
8383
})

docs/asciidoc/getting-started.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ A code example will looks like:
9090
[source, kotlin, role = "secondary"]
9191
----
9292
{
93-
get("/") { ctx -> "Snippet" }
93+
get("/") { "Snippet" }
9494
}
9595
----
9696

docs/asciidoc/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import io.jooby.runApp
5050
5151
fun main(args: Array<String>) {
5252
runApp(args) {
53-
get ("/") { ctx -> "Welcome to Jooby!" }
53+
get ("/") { "Welcome to Jooby!" }
5454
}
5555
}
5656
----
@@ -109,7 +109,7 @@ import io.jooby.runApp;
109109
110110
class App : Kooby({
111111
112-
get("/") { ctx -> "Hello Jooby!" }
112+
get("/") { "Hello Jooby!" }
113113
114114
})
115115
@@ -148,7 +148,7 @@ import io.jooby.runApp
148148
fun main(args: Array<String>) {
149149
runApp(args) {
150150
151-
get("/") { ctx -> "Hello Jooby!" }
151+
get("/") { "Hello Jooby!" }
152152
153153
}
154154
}

0 commit comments

Comments
 (0)