I'm playing with Kitura. I have installed a single router endpoint that looks like:
let router = Router()
router.all() { _, response, next in
response.headers["Content-Type"] = "application/json; charset=utf-8"
next()
}
router.get("/hello") { _, response, next in
response.send("{\"message\": \"Hello World\"}")
next()
}
Kitura.addHTTPServer(onPort: 9143, with: router)
print("Application Server Starting...")
Kitura.run()
I'm really confused/frustrated by this next
closure/callback parameter. Many (maybe outdated?) tutorials don't mention or include it, but if I don't call it, my router hangs and the client response is never sent.
Is there a way for me to avoid having to call this in my RouterHandler
? Or have it called automatically? It seems a huge source of potential human error to need to manually execute this callback in every method, and it adds clutter. (Other frameworks like Spring Web execute the chain automatically, there's no next()
call required.)