How to pass computed result to multiple Kitura handler block?

54 Views Asked by At

As we can call multiple handler from router get request, how do we pass, say the result computed in the first handler to the next handler block ?

// Uses multiple handler blocks
    router.get("/multi", handler: { request, response, next in
        response.send("I'm here!\n")
        next()
        }, { request, response, next in
            response.send("Me too!\n")
            next()
    })
1

There are 1 best solutions below

0
On BEST ANSWER

You can use the userInfo dictionary to hold computed data in the request object, and it'll be accessible in the subsequent handlers.

https://ibm-swift.github.io/Kitura/Classes/RouterRequest.html#/s:vC6Kitura13RouterRequest8userInfoGVs10DictionarySSP__