-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-40 Rename reactive plugin to
Coroutines
routing component
- Loading branch information
Showing
7 changed files
with
70 additions
and
61 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
routing-coroutines/src/main/kotlin/io/javalin/community/routing/coroutines/Coroutines.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.javalin.community.routing.coroutines | ||
|
||
import io.javalin.community.routing.coroutines.servlet.CoroutinesServlet | ||
import io.javalin.community.routing.sortRoutes | ||
import io.javalin.config.JavalinConfig | ||
import io.javalin.http.Handler | ||
import io.javalin.http.HandlerType | ||
import io.javalin.router.InternalRouter | ||
import io.javalin.router.RoutingApiInitializer | ||
import java.util.function.Consumer | ||
|
||
class Coroutines<ROUTE : SuspendedRoute<CONTEXT, RESPONSE>, CONTEXT, RESPONSE : Any>( | ||
private val servlet: CoroutinesServlet<CONTEXT, RESPONSE>, | ||
) : RoutingApiInitializer<CoroutinesRouting<ROUTE, CONTEXT, RESPONSE>> { | ||
|
||
override fun initialize(cfg: JavalinConfig, internalRouter: InternalRouter, setup: Consumer<CoroutinesRouting<ROUTE, CONTEXT, RESPONSE>>) { | ||
val coroutinesRouting = CoroutinesRouting<ROUTE, CONTEXT, RESPONSE>() | ||
setup.accept(coroutinesRouting) | ||
|
||
coroutinesRouting | ||
.routes | ||
.sortRoutes() | ||
.map { it to Handler { ctx -> servlet.handle(ctx, it) } } | ||
.forEach { (route, handler) -> internalRouter.addHttpHandler(HandlerType.valueOf(route.method.toString()), route.path, handler) } | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...g-coroutines/src/main/kotlin/io/javalin/community/routing/coroutines/CoroutinesRouting.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.javalin.community.routing.coroutines | ||
|
||
import io.javalin.community.routing.Route | ||
|
||
class CoroutinesRouting<ROUTE : SuspendedRoute<CONTEXT, RESPONSE>, CONTEXT, RESPONSE : Any> { | ||
|
||
internal val routes = mutableListOf<ROUTE>() | ||
|
||
fun route(route: ROUTE) { | ||
routes.add(route) | ||
} | ||
|
||
fun routes(exampleEndpoint: SuspendedRoutes<ROUTE, CONTEXT, RESPONSE>): CoroutinesRouting<ROUTE, CONTEXT, RESPONSE> { | ||
exampleEndpoint.routes().forEach { route(it) } | ||
return this | ||
} | ||
|
||
} | ||
|
||
fun <CONTEXT, RESPONSE : Any> CoroutinesRouting<SuspendedRoute<CONTEXT, RESPONSE>, CONTEXT, RESPONSE>.route( | ||
method: Route, | ||
path: String, | ||
async: Boolean = true, | ||
handler: suspend CONTEXT.() -> RESPONSE | ||
) { | ||
routes.add(SuspendedRoute(path, method, async, handler)) | ||
} |
46 changes: 0 additions & 46 deletions
46
...routines/src/main/kotlin/io/javalin/community/routing/coroutines/ReactiveRoutingPlugin.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters