https://kotlinlang.org logo
Title
j

jackmiras

05/24/2017, 6:22 PM
I've ben using Spark with kotlin for a couple months know and works realy fine. However I do not agree with the route system and because of that I've implement a diferent route system over the framework routes. If you try Use Spark you will end up with endpoints like:
post("/endpoint", {request, response ->  <http://someController.post|someController.post>(request, response)})
get("/endpoint", {request, response ->  someController.get(request, response)})
put("/endpoint", {request, response ->  someController.put(request, response)})
delete("/endpoint", {request, response ->  someController.delete(request, response)})
The change that I made in my project allows me to implement endpoints like this:
route("/endpoint")
    .get { request, response -> someController.get(request, response) }
    .post { request, response -> <http://someController.post|someController.post>(request, response) }
    .put { request, response -> someController.put(request, response) }
    .delete { request, response -> someController.delete(request, response) }
And if you have a path at you url you I can do something like:
route("/users")
    .post { request, response -> <http://userController.post|userController.post>(request, response) }
    .post("/signin", { request, response -> userController.signin(request, response) })
    .post("/signout", { request, response -> userController.signout(request, response) })
You can do the same with Spark routes but you will have to write a little more code and for me this "node like" endpoint implementation works better.
j

juliocbcotta

05/24/2017, 6:49 PM
jackmiras: it looks like the
path
in this doc http://sparkjava.com/documentation#routes
do you have your change in a github or lib?
j

jackmiras

05/24/2017, 6:51 PM
Nope
I can send you the code if you want because I think that is almost impossible the guys from Spark change the route system to something like this implementation that I did based on Node endpoints