efemoney
08/31/2020, 3:08 AM/**
* Compose multiple pipeline [interceptors] into one. This executes [interceptors] in a new pipeline running in this
* interceptors context on this interceptors subject
*
* @return A [PipelineInterceptor] that executes other [interceptors] in a pipeline within its own context on its own subject
* @param interceptors [PipelineInterceptor]s to execute **serially**
*/
fun <TSubject : Any, TContext : Any> compose(
vararg interceptors: PipelineInterceptor<TSubject, TContext>
): PipelineInterceptor<TSubject, TContext> = {
val pipeline = Pipeline(PipelinePhase("Compose"), interceptors.asList())
pipeline.execute(context, subject)
}
with usage:
route("/api") {
get("/comics", GetAllComics)
get("/comics/{page}", GetComicPage)
get("/comics/latest", GetComicLatest)
put("/users/token", compose(AuthenticateUser, SaveUserToken))
put("/users/page", compose(AuthenticateUser, SaveUserPage))
}
I am trying to get the same behavior as nodejs’s express
interceptors.Jorge R
08/31/2020, 8:56 AMefemoney
08/31/2020, 5:27 PMJorge R
09/01/2020, 1:30 PMefemoney
09/01/2020, 4:24 PM